From 51e9e1500b18a5ce55f90085f1397ef8f6c3d1cf Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Wed, 6 Jan 2021 18:52:06 +0000 Subject: [PATCH] add docs to recent additions --- actix-http/src/h1/dispatcher.rs | 16 ++++++++-------- actix-http/src/h1/service.rs | 14 +++++++------- actix-http/src/h2/dispatcher.rs | 6 +++--- actix-http/src/h2/service.rs | 8 ++++---- actix-http/src/lib.rs | 9 ++++++--- actix-http/src/service.rs | 18 +++++++++--------- 6 files changed, 37 insertions(+), 34 deletions(-) diff --git a/actix-http/src/h1/dispatcher.rs b/actix-http/src/h1/dispatcher.rs index 60552d102..a914880ce 100644 --- a/actix-http/src/h1/dispatcher.rs +++ b/actix-http/src/h1/dispatcher.rs @@ -91,7 +91,7 @@ where U: Service<(Request, Framed), Response = ()>, U::Error: fmt::Display, { - services: Rc>>, + flow: Rc>>, on_connect_data: OnConnectData, flags: Flags, peer_addr: Option, @@ -230,7 +230,7 @@ where io: Some(io), codec, read_buf, - services, + flow: services, on_connect_data, flags, peer_addr, @@ -384,7 +384,7 @@ where Poll::Ready(Ok(req)) => { self.as_mut().send_continue(); 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)); continue; } @@ -474,12 +474,12 @@ where if req.head().expect() { // set dispatcher state so the future is pinned. 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)); } else { // the same as above. 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)); }; @@ -492,7 +492,7 @@ where Poll::Ready(Ok(req)) => { self.as_mut().send_continue(); 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)); continue; } @@ -564,7 +564,7 @@ where this.on_connect_data.merge_into(&mut req); if pl == MessageType::Stream - && this.services.borrow().upgrade.is_some() + && this.flow.borrow().upgrade.is_some() { this.messages.push_back(DispatcherMessage::Upgrade(req)); break; @@ -830,7 +830,7 @@ where parts.write_buf = mem::take(inner_p.write_buf); let framed = Framed::from_parts(parts); let upgrade = inner_p - .services + .flow .borrow_mut() .upgrade .take() diff --git a/actix-http/src/h1/service.rs b/actix-http/src/h1/service.rs index 19272c133..067c8b647 100644 --- a/actix-http/src/h1/service.rs +++ b/actix-http/src/h1/service.rs @@ -367,7 +367,7 @@ where X: Service, U: Service<(Request, Framed)>, { - services: Rc>>, + flow: Rc>>, on_connect_ext: Option>>, cfg: ServiceConfig, _phantom: PhantomData, @@ -392,7 +392,7 @@ where on_connect_ext: Option>>, ) -> H1ServiceHandler { H1ServiceHandler { - services: HttpFlow::new(service, expect, upgrade), + flow: HttpFlow::new(service, expect, upgrade), cfg, on_connect_ext, _phantom: PhantomData, @@ -418,8 +418,8 @@ where type Future = Dispatcher; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - let mut services = self.services.borrow_mut(); - let ready = services + let mut flow = self.flow.borrow_mut(); + let ready = flow .expect .poll_ready(cx) .map_err(|e| { @@ -429,7 +429,7 @@ where })? .is_ready(); - let ready = services + let ready = flow .service .poll_ready(cx) .map_err(|e| { @@ -440,7 +440,7 @@ where .is_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) .map_err(|e| { let e = e.into(); @@ -467,7 +467,7 @@ where Dispatcher::new( io, self.cfg.clone(), - self.services.clone(), + self.flow.clone(), on_connect_data, addr, ) diff --git a/actix-http/src/h2/dispatcher.rs b/actix-http/src/h2/dispatcher.rs index 621035869..959c34f13 100644 --- a/actix-http/src/h2/dispatcher.rs +++ b/actix-http/src/h2/dispatcher.rs @@ -37,7 +37,7 @@ where S: Service, B: MessageBody, { - services: Rc>>, + flow: Rc>>, connection: Connection, on_connect_data: OnConnectData, config: ServiceConfig, @@ -80,7 +80,7 @@ where }; Dispatcher { - services, + flow: services, config, peer_addr, connection, @@ -138,7 +138,7 @@ where let svc = ServiceResponse:: { state: ServiceResponseState::ServiceCall( - this.services.borrow_mut().service.call(req), + this.flow.borrow_mut().service.call(req), Some(res), ), config: this.config.clone(), diff --git a/actix-http/src/h2/service.rs b/actix-http/src/h2/service.rs index f94aae79e..95ff3de26 100644 --- a/actix-http/src/h2/service.rs +++ b/actix-http/src/h2/service.rs @@ -249,7 +249,7 @@ pub struct H2ServiceHandler where S: Service, { - services: Rc>>, + flow: Rc>>, cfg: ServiceConfig, on_connect_ext: Option>>, _phantom: PhantomData, @@ -269,7 +269,7 @@ where service: S, ) -> H2ServiceHandler { H2ServiceHandler { - services: HttpFlow::new(service, (), None), + flow: HttpFlow::new(service, (), None), cfg, on_connect_ext, _phantom: PhantomData, @@ -291,7 +291,7 @@ where type Future = H2ServiceHandlerResponse; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - self.services + self.flow .borrow_mut() .service .poll_ready(cx) @@ -308,7 +308,7 @@ where H2ServiceHandlerResponse { state: State::Handshake( - Some(self.services.clone()), + Some(self.flow.clone()), Some(self.cfg.clone()), addr, on_connect_data, diff --git a/actix-http/src/lib.rs b/actix-http/src/lib.rs index 0c58df2ed..3879bae81 100644 --- a/actix-http/src/lib.rs +++ b/actix-http/src/lib.rs @@ -72,7 +72,7 @@ pub mod http { pub use crate::message::ConnectionType; } -/// Http protocol +/// HTTP protocol #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] pub enum Protocol { Http1, @@ -82,6 +82,9 @@ pub enum Protocol { type ConnectCallback = dyn Fn(&IO, &mut Extensions); /// 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); impl Default for OnConnectData { @@ -91,7 +94,7 @@ impl Default for 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( io: &T, on_connect_ext: Option<&ConnectCallback>, @@ -105,7 +108,7 @@ impl OnConnectData { Self(ext) } - // merge self to given request's head extension. + /// Merge self into given request's extensions. #[inline] pub(crate) fn merge_into(&mut self, req: &mut Request) { if let Some(ref mut ext) = self.0 { diff --git a/actix-http/src/service.rs b/actix-http/src/service.rs index eb16a6e70..e137ab6fa 100644 --- a/actix-http/src/service.rs +++ b/actix-http/src/service.rs @@ -441,13 +441,13 @@ where X: Service, U: Service<(Request, Framed)>, { - services: Rc>>, + flow: Rc>>, cfg: ServiceConfig, on_connect_ext: Option>>, _phantom: PhantomData, } -// a collection of service for http. +/// A collection of services that describe an HTTP request flow. pub(super) struct HttpFlow { pub(super) service: S, pub(super) expect: X, @@ -486,7 +486,7 @@ where HttpServiceHandler { cfg, on_connect_ext, - services: HttpFlow::new(service, expect, upgrade), + flow: HttpFlow::new(service, expect, upgrade), _phantom: PhantomData, } } @@ -511,8 +511,8 @@ where type Future = HttpServiceHandlerResponse; fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { - let mut services = self.services.borrow_mut(); - let ready = services + let mut flow = self.flow.borrow_mut(); + let ready = flow .expect .poll_ready(cx) .map_err(|e| { @@ -522,7 +522,7 @@ where })? .is_ready(); - let ready = services + let ready = flow .service .poll_ready(cx) .map_err(|e| { @@ -533,7 +533,7 @@ where .is_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) .map_err(|e| { let e = e.into(); @@ -565,7 +565,7 @@ where state: State::H2Handshake(Some(( server::handshake(io), self.cfg.clone(), - self.services.clone(), + self.flow.clone(), on_connect_data, peer_addr, ))), @@ -575,7 +575,7 @@ where state: State::H1(h1::Dispatcher::new( io, self.cfg.clone(), - self.services.clone(), + self.flow.clone(), on_connect_data, peer_addr, )),