Skip to content

Commit

Permalink
start working towards http connector
Browse files Browse the repository at this point in the history
  • Loading branch information
glendc committed Nov 4, 2023
1 parent f09c395 commit acb418d
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
2 changes: 1 addition & 1 deletion rama-old/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT OR Apache-2.0"
repository = "/~https://github.com/plabayo/rama"

[[bin]]
name = "rama"
name = "rama-old"
path = "./bin/main.rs"

[features]
Expand Down
1 change: 1 addition & 0 deletions rama/src/server/http/conn.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct HttpConnection;
3 changes: 3 additions & 0 deletions rama/src/server/http/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
pub mod service;

mod conn;
pub use conn::HttpConnection;
20 changes: 11 additions & 9 deletions rama/src/server/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tokio::{
net::TcpStream as TokioTcpStream,
};

use crate::state::Extensions;
use crate::state::{Extendable, Extensions};

pin_project_lite::pin_project! {
#[derive(Debug)]
Expand All @@ -29,14 +29,6 @@ impl TcpStream {
}
}

pub fn extensions(&self) -> &Extensions {
&self.extensions
}

pub fn extensions_mut(&mut self) -> &mut Extensions {
&mut self.extensions
}

pub fn peer_addr(&self) -> io::Result<SocketAddr> {
self.inner.peer_addr()
}
Expand All @@ -54,6 +46,16 @@ impl TcpStream {
}
}

impl Extendable for TcpStream {
fn extensions(&self) -> &Extensions {
&self.extensions
}

fn extensions_mut(&mut self) -> &mut Extensions {
&mut self.extensions
}
}

impl AsyncRead for TcpStream {
fn poll_read(
self: Pin<&mut Self>,
Expand Down
35 changes: 35 additions & 0 deletions rama/src/state.rs
Original file line number Diff line number Diff line change
@@ -1 +1,36 @@
pub use http::Extensions;

pub trait Extendable {
fn extensions(&self) -> &Extensions;
fn extensions_mut(&mut self) -> &mut Extensions;
}

impl Extendable for Extensions {
fn extensions(&self) -> &Extensions {
self
}

fn extensions_mut(&mut self) -> &mut Extensions {
self
}
}

impl<T> Extendable for http::Request<T> {
fn extensions(&self) -> &Extensions {
self.extensions()
}

fn extensions_mut(&mut self) -> &mut Extensions {
self.extensions_mut()
}
}

impl<T> Extendable for http::Response<T> {
fn extensions(&self) -> &Extensions {
self.extensions()
}

fn extensions_mut(&mut self) -> &mut Extensions {
self.extensions_mut()
}
}

0 comments on commit acb418d

Please sign in to comment.