1
0
mirror of https://github.com/fafhrd91/actix-web synced 2024-12-18 01:43:58 +01:00

add docs to recent additions

This commit is contained in:
Rob Ede 2021-01-06 18:52:06 +00:00
parent a03dbe2dcf
commit 51e9e1500b
No known key found for this signature in database
GPG Key ID: C2A3B36E841A91E6
6 changed files with 37 additions and 34 deletions

View File

@ -91,7 +91,7 @@ where
U: Service<(Request, Framed<T, Codec>), Response = ()>, U: Service<(Request, Framed<T, Codec>), Response = ()>,
U::Error: fmt::Display, U::Error: fmt::Display,
{ {
services: Rc<RefCell<HttpFlow<S, X, U>>>, flow: Rc<RefCell<HttpFlow<S, X, U>>>,
on_connect_data: OnConnectData, on_connect_data: OnConnectData,
flags: Flags, flags: Flags,
peer_addr: Option<net::SocketAddr>, peer_addr: Option<net::SocketAddr>,
@ -230,7 +230,7 @@ where
io: Some(io), io: Some(io),
codec, codec,
read_buf, read_buf,
services, flow: services,
on_connect_data, on_connect_data,
flags, flags,
peer_addr, peer_addr,
@ -384,7 +384,7 @@ where
Poll::Ready(Ok(req)) => { Poll::Ready(Ok(req)) => {
self.as_mut().send_continue(); self.as_mut().send_continue();
this = self.as_mut().project(); this = self.as_mut().project();
let fut = this.services.borrow_mut().service.call(req); let fut = this.flow.borrow_mut().service.call(req);
this.state.set(State::ServiceCall(fut)); this.state.set(State::ServiceCall(fut));
continue; continue;
} }
@ -474,12 +474,12 @@ where
if req.head().expect() { if req.head().expect() {
// set dispatcher state so the future is pinned. // set dispatcher state so the future is pinned.
let mut this = self.as_mut().project(); let mut this = self.as_mut().project();
let task = this.services.borrow_mut().expect.call(req); let task = this.flow.borrow_mut().expect.call(req);
this.state.set(State::ExpectCall(task)); this.state.set(State::ExpectCall(task));
} else { } else {
// the same as above. // the same as above.
let mut this = self.as_mut().project(); let mut this = self.as_mut().project();
let task = this.services.borrow_mut().service.call(req); let task = this.flow.borrow_mut().service.call(req);
this.state.set(State::ServiceCall(task)); this.state.set(State::ServiceCall(task));
}; };
@ -492,7 +492,7 @@ where
Poll::Ready(Ok(req)) => { Poll::Ready(Ok(req)) => {
self.as_mut().send_continue(); self.as_mut().send_continue();
let mut this = self.as_mut().project(); let mut this = self.as_mut().project();
let task = this.services.borrow_mut().service.call(req); let task = this.flow.borrow_mut().service.call(req);
this.state.set(State::ServiceCall(task)); this.state.set(State::ServiceCall(task));
continue; continue;
} }
@ -564,7 +564,7 @@ where
this.on_connect_data.merge_into(&mut req); this.on_connect_data.merge_into(&mut req);
if pl == MessageType::Stream if pl == MessageType::Stream
&& this.services.borrow().upgrade.is_some() && this.flow.borrow().upgrade.is_some()
{ {
this.messages.push_back(DispatcherMessage::Upgrade(req)); this.messages.push_back(DispatcherMessage::Upgrade(req));
break; break;
@ -830,7 +830,7 @@ where
parts.write_buf = mem::take(inner_p.write_buf); parts.write_buf = mem::take(inner_p.write_buf);
let framed = Framed::from_parts(parts); let framed = Framed::from_parts(parts);
let upgrade = inner_p let upgrade = inner_p
.services .flow
.borrow_mut() .borrow_mut()
.upgrade .upgrade
.take() .take()

View File

@ -367,7 +367,7 @@ where
X: Service<Request>, X: Service<Request>,
U: Service<(Request, Framed<T, Codec>)>, U: Service<(Request, Framed<T, Codec>)>,
{ {
services: Rc<RefCell<HttpFlow<S, X, U>>>, flow: Rc<RefCell<HttpFlow<S, X, U>>>,
on_connect_ext: Option<Rc<ConnectCallback<T>>>, on_connect_ext: Option<Rc<ConnectCallback<T>>>,
cfg: ServiceConfig, cfg: ServiceConfig,
_phantom: PhantomData<B>, _phantom: PhantomData<B>,
@ -392,7 +392,7 @@ where
on_connect_ext: Option<Rc<ConnectCallback<T>>>, on_connect_ext: Option<Rc<ConnectCallback<T>>>,
) -> H1ServiceHandler<T, S, B, X, U> { ) -> H1ServiceHandler<T, S, B, X, U> {
H1ServiceHandler { H1ServiceHandler {
services: HttpFlow::new(service, expect, upgrade), flow: HttpFlow::new(service, expect, upgrade),
cfg, cfg,
on_connect_ext, on_connect_ext,
_phantom: PhantomData, _phantom: PhantomData,
@ -418,8 +418,8 @@ where
type Future = Dispatcher<T, S, B, X, U>; type Future = Dispatcher<T, S, B, X, U>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
let mut services = self.services.borrow_mut(); let mut flow = self.flow.borrow_mut();
let ready = services let ready = flow
.expect .expect
.poll_ready(cx) .poll_ready(cx)
.map_err(|e| { .map_err(|e| {
@ -429,7 +429,7 @@ where
})? })?
.is_ready(); .is_ready();
let ready = services let ready = flow
.service .service
.poll_ready(cx) .poll_ready(cx)
.map_err(|e| { .map_err(|e| {
@ -440,7 +440,7 @@ where
.is_ready() .is_ready()
&& ready; && ready;
let ready = if let Some(ref mut upg) = services.upgrade { let ready = if let Some(ref mut upg) = flow.upgrade {
upg.poll_ready(cx) upg.poll_ready(cx)
.map_err(|e| { .map_err(|e| {
let e = e.into(); let e = e.into();
@ -467,7 +467,7 @@ where
Dispatcher::new( Dispatcher::new(
io, io,
self.cfg.clone(), self.cfg.clone(),
self.services.clone(), self.flow.clone(),
on_connect_data, on_connect_data,
addr, addr,
) )

View File

@ -37,7 +37,7 @@ where
S: Service<Request>, S: Service<Request>,
B: MessageBody, B: MessageBody,
{ {
services: Rc<RefCell<HttpFlow<S, X, U>>>, flow: Rc<RefCell<HttpFlow<S, X, U>>>,
connection: Connection<T, Bytes>, connection: Connection<T, Bytes>,
on_connect_data: OnConnectData, on_connect_data: OnConnectData,
config: ServiceConfig, config: ServiceConfig,
@ -80,7 +80,7 @@ where
}; };
Dispatcher { Dispatcher {
services, flow: services,
config, config,
peer_addr, peer_addr,
connection, connection,
@ -138,7 +138,7 @@ where
let svc = ServiceResponse::<S::Future, S::Response, S::Error, B> { let svc = ServiceResponse::<S::Future, S::Response, S::Error, B> {
state: ServiceResponseState::ServiceCall( state: ServiceResponseState::ServiceCall(
this.services.borrow_mut().service.call(req), this.flow.borrow_mut().service.call(req),
Some(res), Some(res),
), ),
config: this.config.clone(), config: this.config.clone(),

View File

@ -249,7 +249,7 @@ pub struct H2ServiceHandler<T, S, B>
where where
S: Service<Request>, S: Service<Request>,
{ {
services: Rc<RefCell<HttpFlow<S, (), ()>>>, flow: Rc<RefCell<HttpFlow<S, (), ()>>>,
cfg: ServiceConfig, cfg: ServiceConfig,
on_connect_ext: Option<Rc<ConnectCallback<T>>>, on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_phantom: PhantomData<B>, _phantom: PhantomData<B>,
@ -269,7 +269,7 @@ where
service: S, service: S,
) -> H2ServiceHandler<T, S, B> { ) -> H2ServiceHandler<T, S, B> {
H2ServiceHandler { H2ServiceHandler {
services: HttpFlow::new(service, (), None), flow: HttpFlow::new(service, (), None),
cfg, cfg,
on_connect_ext, on_connect_ext,
_phantom: PhantomData, _phantom: PhantomData,
@ -291,7 +291,7 @@ where
type Future = H2ServiceHandlerResponse<T, S, B>; type Future = H2ServiceHandlerResponse<T, S, B>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
self.services self.flow
.borrow_mut() .borrow_mut()
.service .service
.poll_ready(cx) .poll_ready(cx)
@ -308,7 +308,7 @@ where
H2ServiceHandlerResponse { H2ServiceHandlerResponse {
state: State::Handshake( state: State::Handshake(
Some(self.services.clone()), Some(self.flow.clone()),
Some(self.cfg.clone()), Some(self.cfg.clone()),
addr, addr,
on_connect_data, on_connect_data,

View File

@ -72,7 +72,7 @@ pub mod http {
pub use crate::message::ConnectionType; pub use crate::message::ConnectionType;
} }
/// Http protocol /// HTTP protocol
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)]
pub enum Protocol { pub enum Protocol {
Http1, Http1,
@ -82,6 +82,9 @@ pub enum Protocol {
type ConnectCallback<IO> = dyn Fn(&IO, &mut Extensions); type ConnectCallback<IO> = dyn Fn(&IO, &mut Extensions);
/// Container for data that extract with ConnectCallback. /// Container for data that extract with ConnectCallback.
///
/// # Implementation Details
/// Uses Option to reduce necessary allocations when merging with request extensions.
pub(crate) struct OnConnectData(Option<Extensions>); pub(crate) struct OnConnectData(Option<Extensions>);
impl Default for OnConnectData { impl Default for OnConnectData {
@ -91,7 +94,7 @@ impl Default for OnConnectData {
} }
impl OnConnectData { impl OnConnectData {
// construct self from io. /// Construct by calling the on-connect callback with the underlying transport I/O.
pub(crate) fn from_io<T>( pub(crate) fn from_io<T>(
io: &T, io: &T,
on_connect_ext: Option<&ConnectCallback<T>>, on_connect_ext: Option<&ConnectCallback<T>>,
@ -105,7 +108,7 @@ impl OnConnectData {
Self(ext) Self(ext)
} }
// merge self to given request's head extension. /// Merge self into given request's extensions.
#[inline] #[inline]
pub(crate) fn merge_into(&mut self, req: &mut Request) { pub(crate) fn merge_into(&mut self, req: &mut Request) {
if let Some(ref mut ext) = self.0 { if let Some(ref mut ext) = self.0 {

View File

@ -441,13 +441,13 @@ where
X: Service<Request>, X: Service<Request>,
U: Service<(Request, Framed<T, h1::Codec>)>, U: Service<(Request, Framed<T, h1::Codec>)>,
{ {
services: Rc<RefCell<HttpFlow<S, X, U>>>, flow: Rc<RefCell<HttpFlow<S, X, U>>>,
cfg: ServiceConfig, cfg: ServiceConfig,
on_connect_ext: Option<Rc<ConnectCallback<T>>>, on_connect_ext: Option<Rc<ConnectCallback<T>>>,
_phantom: PhantomData<B>, _phantom: PhantomData<B>,
} }
// a collection of service for http. /// A collection of services that describe an HTTP request flow.
pub(super) struct HttpFlow<S, X, U> { pub(super) struct HttpFlow<S, X, U> {
pub(super) service: S, pub(super) service: S,
pub(super) expect: X, pub(super) expect: X,
@ -486,7 +486,7 @@ where
HttpServiceHandler { HttpServiceHandler {
cfg, cfg,
on_connect_ext, on_connect_ext,
services: HttpFlow::new(service, expect, upgrade), flow: HttpFlow::new(service, expect, upgrade),
_phantom: PhantomData, _phantom: PhantomData,
} }
} }
@ -511,8 +511,8 @@ where
type Future = HttpServiceHandlerResponse<T, S, B, X, U>; type Future = HttpServiceHandlerResponse<T, S, B, X, U>;
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
let mut services = self.services.borrow_mut(); let mut flow = self.flow.borrow_mut();
let ready = services let ready = flow
.expect .expect
.poll_ready(cx) .poll_ready(cx)
.map_err(|e| { .map_err(|e| {
@ -522,7 +522,7 @@ where
})? })?
.is_ready(); .is_ready();
let ready = services let ready = flow
.service .service
.poll_ready(cx) .poll_ready(cx)
.map_err(|e| { .map_err(|e| {
@ -533,7 +533,7 @@ where
.is_ready() .is_ready()
&& ready; && ready;
let ready = if let Some(ref mut upg) = services.upgrade { let ready = if let Some(ref mut upg) = flow.upgrade {
upg.poll_ready(cx) upg.poll_ready(cx)
.map_err(|e| { .map_err(|e| {
let e = e.into(); let e = e.into();
@ -565,7 +565,7 @@ where
state: State::H2Handshake(Some(( state: State::H2Handshake(Some((
server::handshake(io), server::handshake(io),
self.cfg.clone(), self.cfg.clone(),
self.services.clone(), self.flow.clone(),
on_connect_data, on_connect_data,
peer_addr, peer_addr,
))), ))),
@ -575,7 +575,7 @@ where
state: State::H1(h1::Dispatcher::new( state: State::H1(h1::Dispatcher::new(
io, io,
self.cfg.clone(), self.cfg.clone(),
self.services.clone(), self.flow.clone(),
on_connect_data, on_connect_data,
peer_addr, peer_addr,
)), )),