From ae5c4dfb7812caaa95b550f379fa3312dd6fcd01 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Tue, 2 Oct 2018 15:25:32 -0700 Subject: [PATCH] refactor http channels list; rename WorkerSettings --- src/client/connector.rs | 1 + src/server/acceptor.rs | 17 +++-- src/server/builder.rs | 4 +- src/server/channel.rs | 148 ++++++++++++++++++++-------------------- src/server/h1.rs | 32 ++++----- src/server/h1decoder.rs | 6 +- src/server/h1writer.rs | 6 +- src/server/h2.rs | 10 +-- src/server/h2writer.rs | 8 +-- src/server/incoming.rs | 6 +- src/server/mod.rs | 2 +- src/server/service.rs | 20 ++++-- src/server/settings.rs | 43 ++++++------ tests/test_server.rs | 4 +- 14 files changed, 157 insertions(+), 150 deletions(-) diff --git a/src/client/connector.rs b/src/client/connector.rs index 90a2e1c88..07c7b646d 100644 --- a/src/client/connector.rs +++ b/src/client/connector.rs @@ -293,6 +293,7 @@ impl Default for ClientConnector { } }; + #[cfg_attr(feature = "cargo-clippy", allow(clippy::let_unit_value))] ClientConnector::with_connector_impl(connector) } } diff --git a/src/server/acceptor.rs b/src/server/acceptor.rs index 3dcd8ac88..79d133d2d 100644 --- a/src/server/acceptor.rs +++ b/src/server/acceptor.rs @@ -9,9 +9,10 @@ use tokio_reactor::Handle; use tokio_tcp::TcpStream; use tokio_timer::{sleep, Delay}; +use super::channel::HttpProtocol; use super::error::AcceptorError; use super::handler::HttpHandler; -use super::settings::WorkerSettings; +use super::settings::ServiceConfig; use super::IoStream; /// This trait indicates types that can create acceptor service for http server. @@ -271,7 +272,7 @@ impl Future for AcceptorTimeoutResponse { pub(crate) struct ServerMessageAcceptor { inner: T, - settings: WorkerSettings, + settings: ServiceConfig, } impl ServerMessageAcceptor @@ -279,7 +280,7 @@ where H: HttpHandler, T: NewService, { - pub(crate) fn new(settings: WorkerSettings, inner: T) -> Self { + pub(crate) fn new(settings: ServiceConfig, inner: T) -> Self { ServerMessageAcceptor { inner, settings } } } @@ -310,7 +311,7 @@ where T: NewService, { fut: T::Future, - settings: WorkerSettings, + settings: ServiceConfig, } impl Future for ServerMessageAcceptorResponse @@ -334,7 +335,7 @@ where pub(crate) struct ServerMessageAcceptorService { inner: T, - settings: WorkerSettings, + settings: ServiceConfig, } impl Service for ServerMessageAcceptorService @@ -359,9 +360,11 @@ where fut: self.inner.call(stream), }) } - ServerMessage::Shutdown(timeout) => Either::B(ok(())), + ServerMessage::Shutdown(_) => Either::B(ok(())), ServerMessage::ForceShutdown => { - // self.settings.head().traverse::(); + self.settings + .head() + .traverse(|proto: &mut HttpProtocol| proto.shutdown()); Either::B(ok(())) } } diff --git a/src/server/builder.rs b/src/server/builder.rs index 8a979752e..ec6ce9923 100644 --- a/src/server/builder.rs +++ b/src/server/builder.rs @@ -10,7 +10,7 @@ use super::acceptor::{ use super::error::AcceptorError; use super::handler::IntoHttpHandler; use super::service::HttpService; -use super::settings::{ServerSettings, WorkerSettings}; +use super::settings::{ServerSettings, ServiceConfig}; use super::KeepAlive; pub(crate) trait ServiceProvider { @@ -50,7 +50,7 @@ where let acceptor = self.acceptor.clone(); move || { let app = (factory)().into_handler(); - let settings = WorkerSettings::new( + let settings = ServiceConfig::new( app, keep_alive, client_timeout, diff --git a/src/server/channel.rs b/src/server/channel.rs index f57806209..513601ac9 100644 --- a/src/server/channel.rs +++ b/src/server/channel.rs @@ -1,5 +1,5 @@ use std::net::{Shutdown, SocketAddr}; -use std::{io, ptr, time}; +use std::{io, mem, time}; use bytes::{Buf, BufMut, BytesMut}; use futures::{Async, Future, Poll}; @@ -7,16 +7,35 @@ use tokio_io::{AsyncRead, AsyncWrite}; use tokio_timer::Delay; use super::error::HttpDispatchError; -use super::settings::WorkerSettings; +use super::settings::ServiceConfig; use super::{h1, h2, HttpHandler, IoStream}; use http::StatusCode; const HTTP2_PREFACE: [u8; 14] = *b"PRI * HTTP/2.0"; -enum HttpProtocol { +pub(crate) enum HttpProtocol { H1(h1::Http1Dispatcher), H2(h2::Http2), - Unknown(WorkerSettings, Option, T, BytesMut), + Unknown(ServiceConfig, Option, T, BytesMut), + None, +} + +impl HttpProtocol { + pub(crate) fn shutdown(&mut self) { + match self { + HttpProtocol::H1(ref mut h1) => { + let io = h1.io(); + let _ = IoStream::set_linger(io, Some(time::Duration::new(0, 0))); + let _ = IoStream::shutdown(io, Shutdown::Both); + } + HttpProtocol::H2(ref mut h2) => h2.shutdown(), + HttpProtocol::Unknown(_, _, io, _) => { + let _ = IoStream::set_linger(io, Some(time::Duration::new(0, 0))); + let _ = IoStream::shutdown(io, Shutdown::Both); + } + HttpProtocol::None => (), + } + } } enum ProtocolKind { @@ -30,8 +49,8 @@ where T: IoStream, H: HttpHandler + 'static, { - proto: Option>, - node: Option>>, + node: Node>, + node_reg: bool, ka_timeout: Option, } @@ -41,12 +60,14 @@ where H: HttpHandler + 'static, { pub(crate) fn new( - settings: WorkerSettings, io: T, peer: Option, + settings: ServiceConfig, io: T, peer: Option, ) -> HttpChannel { + let ka_timeout = settings.client_timer(); + HttpChannel { - node: None, - ka_timeout: settings.client_timer(), - proto: Some(HttpProtocol::Unknown( + ka_timeout, + node_reg: false, + node: Node::new(HttpProtocol::Unknown( settings, peer, io, @@ -54,18 +75,6 @@ where )), } } - - pub(crate) fn shutdown(&mut self) { - match self.proto { - Some(HttpProtocol::H1(ref mut h1)) => { - let io = h1.io(); - let _ = IoStream::set_linger(io, Some(time::Duration::new(0, 0))); - let _ = IoStream::shutdown(io, Shutdown::Both); - } - Some(HttpProtocol::H2(ref mut h2)) => h2.shutdown(), - _ => (), - } - } } impl Drop for HttpChannel @@ -74,9 +83,7 @@ where H: HttpHandler + 'static, { fn drop(&mut self) { - if let Some(mut node) = self.node.take() { - node.remove() - } + self.node.remove(); } } @@ -94,17 +101,16 @@ where match self.ka_timeout.as_mut().unwrap().poll() { Ok(Async::Ready(_)) => { trace!("Slow request timed out, close connection"); - if let Some(HttpProtocol::Unknown(settings, _, io, buf)) = - self.proto.take() - { - self.proto = - Some(HttpProtocol::H1(h1::Http1Dispatcher::for_error( + let proto = mem::replace(self.node.get_mut(), HttpProtocol::None); + if let HttpProtocol::Unknown(settings, _, io, buf) = proto { + *self.node.get_mut() = + HttpProtocol::H1(h1::Http1Dispatcher::for_error( settings, io, StatusCode::REQUEST_TIMEOUT, self.ka_timeout.take(), buf, - ))); + )); return self.poll(); } return Ok(Async::Ready(())); @@ -114,28 +120,22 @@ where } } - if self.node.is_none() { - let el = self as *mut _; - self.node = Some(Node::new(el)); - let _ = match self.proto { - Some(HttpProtocol::H1(ref mut h1)) => { - self.node.as_mut().map(|n| h1.settings().head().insert(n)) - } - Some(HttpProtocol::H2(ref mut h2)) => { - self.node.as_mut().map(|n| h2.settings().head().insert(n)) - } - Some(HttpProtocol::Unknown(ref mut settings, _, _, _)) => { - self.node.as_mut().map(|n| settings.head().insert(n)) - } - None => unreachable!(), + if !self.node_reg { + self.node_reg = true; + let settings = match self.node.get_mut() { + HttpProtocol::H1(ref mut h1) => h1.settings().clone(), + HttpProtocol::H2(ref mut h2) => h2.settings().clone(), + HttpProtocol::Unknown(ref mut settings, _, _, _) => settings.clone(), + HttpProtocol::None => unreachable!(), }; + settings.head().insert(&mut self.node); } let mut is_eof = false; - let kind = match self.proto { - Some(HttpProtocol::H1(ref mut h1)) => return h1.poll(), - Some(HttpProtocol::H2(ref mut h2)) => return h2.poll(), - Some(HttpProtocol::Unknown(_, _, ref mut io, ref mut buf)) => { + let kind = match self.node.get_mut() { + HttpProtocol::H1(ref mut h1) => return h1.poll(), + HttpProtocol::H2(ref mut h2) => return h2.poll(), + HttpProtocol::Unknown(_, _, ref mut io, ref mut buf) => { let mut err = None; let mut disconnect = false; match io.read_available(buf) { @@ -168,31 +168,32 @@ where return Ok(Async::NotReady); } } - None => unreachable!(), + HttpProtocol::None => unreachable!(), }; // upgrade to specific http protocol - if let Some(HttpProtocol::Unknown(settings, addr, io, buf)) = self.proto.take() { + let proto = mem::replace(self.node.get_mut(), HttpProtocol::None); + if let HttpProtocol::Unknown(settings, addr, io, buf) = proto { match kind { ProtocolKind::Http1 => { - self.proto = Some(HttpProtocol::H1(h1::Http1Dispatcher::new( + *self.node.get_mut() = HttpProtocol::H1(h1::Http1Dispatcher::new( settings, io, addr, buf, is_eof, self.ka_timeout.take(), - ))); + )); return self.poll(); } ProtocolKind::Http2 => { - self.proto = Some(HttpProtocol::H2(h2::Http2::new( + *self.node.get_mut() = HttpProtocol::H2(h2::Http2::new( settings, io, addr, buf.freeze(), self.ka_timeout.take(), - ))); + )); return self.poll(); } } @@ -204,18 +205,22 @@ where pub(crate) struct Node { next: Option<*mut Node>, prev: Option<*mut Node>, - element: *mut T, + element: T, } impl Node { - fn new(el: *mut T) -> Self { + fn new(element: T) -> Self { Node { + element, next: None, prev: None, - element: el, } } + fn get_mut(&mut self) -> &mut T { + &mut self.element + } + fn insert(&mut self, next_el: &mut Node) { let next: *mut Node = next_el as *const _ as *mut _; @@ -235,7 +240,6 @@ impl Node { } fn remove(&mut self) { - self.element = ptr::null_mut(); let next = self.next.take(); let prev = self.prev.take(); @@ -257,30 +261,28 @@ impl Node<()> { Node { next: None, prev: None, - element: ptr::null_mut(), + element: (), } } - pub(crate) fn traverse)>(&self, f: F) + pub(crate) fn traverse)>(&self, f: F) where T: IoStream, H: HttpHandler + 'static, { - let mut next = self.next.as_ref(); - loop { - if let Some(n) = next { - unsafe { - let n: &Node<()> = &*(n.as_ref().unwrap() as *const _); - next = n.next.as_ref(); + if let Some(n) = self.next.as_ref() { + unsafe { + let mut next: &mut Node> = + &mut *(n.as_ref().unwrap() as *const _ as *mut _); + loop { + f(&mut next.element); - if !n.element.is_null() { - let ch: &mut HttpChannel = - &mut *(&mut *(n.element as *mut _) as *mut () as *mut _); - f(ch); + next = if let Some(n) = next.next.as_ref() { + &mut **n + } else { + return; } } - } else { - return; } } } diff --git a/src/server/h1.rs b/src/server/h1.rs index af7e65297..53c4e2cf5 100644 --- a/src/server/h1.rs +++ b/src/server/h1.rs @@ -16,7 +16,7 @@ use super::h1decoder::{DecoderError, H1Decoder, Message}; use super::h1writer::H1Writer; use super::handler::{HttpHandler, HttpHandlerTask, HttpHandlerTaskFut}; use super::input::PayloadType; -use super::settings::WorkerSettings; +use super::settings::ServiceConfig; use super::{IoStream, Writer}; const MAX_PIPELINED_MESSAGES: usize = 16; @@ -37,7 +37,7 @@ bitflags! { /// Dispatcher for HTTP/1.1 protocol pub struct Http1Dispatcher { flags: Flags, - settings: WorkerSettings, + settings: ServiceConfig, addr: Option, stream: H1Writer, decoder: H1Decoder, @@ -87,7 +87,7 @@ where H: HttpHandler + 'static, { pub fn new( - settings: WorkerSettings, stream: T, addr: Option, buf: BytesMut, + settings: ServiceConfig, stream: T, addr: Option, buf: BytesMut, is_eof: bool, keepalive_timer: Option, ) -> Self { let (ka_expire, ka_timer) = if let Some(delay) = keepalive_timer { @@ -122,7 +122,7 @@ where } pub(crate) fn for_error( - settings: WorkerSettings, stream: T, status: StatusCode, + settings: ServiceConfig, stream: T, status: StatusCode, mut keepalive_timer: Option, buf: BytesMut, ) -> Self { if let Some(deadline) = settings.client_timer_expire() { @@ -147,7 +147,7 @@ where } #[inline] - pub fn settings(&self) -> &WorkerSettings { + pub fn settings(&self) -> &ServiceConfig { &self.settings } @@ -259,7 +259,7 @@ where Err(err) => { debug!("Error sending data: {}", err); self.client_disconnected(false); - return Err(err.into()); + Err(err.into()) } Ok(Async::Ready(_)) => { // if payload is not consumed we can not use connection @@ -347,10 +347,8 @@ where if self.can_read() && self.tasks.len() < MAX_PIPELINED_MESSAGES { match self.stream.get_mut().read_available(&mut self.buf) { Ok(Async::Ready((read_some, disconnected))) => { - if read_some { - if self.parse()? { - updated = true; - } + if read_some && self.parse()? { + updated = true; } if disconnected { self.client_disconnected(true); @@ -397,11 +395,9 @@ where // if read-backpressure is enabled and we consumed some data. // we may read more dataand retry - if !retry && self.can_read() { - if self.poll_io()? { - retry = self.can_read(); - continue; - } + if !retry && self.can_read() && self.poll_io()? { + retry = self.can_read(); + continue; } break; } @@ -597,11 +593,11 @@ mod tests { use httpmessage::HttpMessage; use server::h1decoder::Message; use server::handler::IntoHttpHandler; - use server::settings::{ServerSettings, WorkerSettings}; + use server::settings::{ServerSettings, ServiceConfig}; use server::{KeepAlive, Request}; - fn wrk_settings() -> WorkerSettings { - WorkerSettings::::new( + fn wrk_settings() -> ServiceConfig { + ServiceConfig::::new( App::new().into_handler(), KeepAlive::Os, 5000, diff --git a/src/server/h1decoder.rs b/src/server/h1decoder.rs index a7531bbbd..434dc42df 100644 --- a/src/server/h1decoder.rs +++ b/src/server/h1decoder.rs @@ -5,7 +5,7 @@ use futures::{Async, Poll}; use httparse; use super::message::{MessageFlags, Request}; -use super::settings::WorkerSettings; +use super::settings::ServiceConfig; use error::ParseError; use http::header::{HeaderName, HeaderValue}; use http::{header, HttpTryFrom, Method, Uri, Version}; @@ -43,7 +43,7 @@ impl H1Decoder { } pub fn decode( - &mut self, src: &mut BytesMut, settings: &WorkerSettings, + &mut self, src: &mut BytesMut, settings: &ServiceConfig, ) -> Result, DecoderError> { // read payload if self.decoder.is_some() { @@ -80,7 +80,7 @@ impl H1Decoder { } fn parse_message( - &self, buf: &mut BytesMut, settings: &WorkerSettings, + &self, buf: &mut BytesMut, settings: &ServiceConfig, ) -> Poll<(Request, Option), ParseError> { // Parse http message let mut has_upgrade = false; diff --git a/src/server/h1writer.rs b/src/server/h1writer.rs index 5c32de3aa..c27a4c44a 100644 --- a/src/server/h1writer.rs +++ b/src/server/h1writer.rs @@ -8,7 +8,7 @@ use tokio_io::AsyncWrite; use super::helpers; use super::output::{Output, ResponseInfo, ResponseLength}; -use super::settings::WorkerSettings; +use super::settings::ServiceConfig; use super::Request; use super::{Writer, WriterState, MAX_WRITE_BUFFER_SIZE}; use body::{Binary, Body}; @@ -37,11 +37,11 @@ pub(crate) struct H1Writer { headers_size: u32, buffer: Output, buffer_capacity: usize, - settings: WorkerSettings, + settings: ServiceConfig, } impl H1Writer { - pub fn new(stream: T, settings: WorkerSettings) -> H1Writer { + pub fn new(stream: T, settings: ServiceConfig) -> H1Writer { H1Writer { flags: Flags::KEEPALIVE, written: 0, diff --git a/src/server/h2.rs b/src/server/h2.rs index 589e77c2d..312b51df9 100644 --- a/src/server/h2.rs +++ b/src/server/h2.rs @@ -22,7 +22,7 @@ use uri::Url; use super::error::{HttpDispatchError, ServerError}; use super::h2writer::H2Writer; use super::input::PayloadType; -use super::settings::WorkerSettings; +use super::settings::ServiceConfig; use super::{HttpHandler, HttpHandlerTask, IoStream, Writer}; bitflags! { @@ -38,7 +38,7 @@ where H: HttpHandler + 'static, { flags: Flags, - settings: WorkerSettings, + settings: ServiceConfig, addr: Option, state: State>, tasks: VecDeque>, @@ -58,7 +58,7 @@ where H: HttpHandler + 'static, { pub fn new( - settings: WorkerSettings, io: T, addr: Option, buf: Bytes, + settings: ServiceConfig, io: T, addr: Option, buf: Bytes, keepalive_timer: Option, ) -> Self { let extensions = io.extensions(); @@ -82,7 +82,7 @@ where self.keepalive_timer.take(); } - pub fn settings(&self) -> &WorkerSettings { + pub fn settings(&self) -> &ServiceConfig { &self.settings } @@ -338,7 +338,7 @@ struct Entry { impl Entry { fn new( parts: Parts, recv: RecvStream, resp: SendResponse, - addr: Option, settings: WorkerSettings, + addr: Option, settings: ServiceConfig, extensions: Option>, ) -> Entry where diff --git a/src/server/h2writer.rs b/src/server/h2writer.rs index 0893b5b62..51d4dce6f 100644 --- a/src/server/h2writer.rs +++ b/src/server/h2writer.rs @@ -14,7 +14,7 @@ use modhttp::Response; use super::helpers; use super::message::Request; use super::output::{Output, ResponseInfo, ResponseLength}; -use super::settings::WorkerSettings; +use super::settings::ServiceConfig; use super::{Writer, WriterState, MAX_WRITE_BUFFER_SIZE}; use body::{Binary, Body}; use header::ContentEncoding; @@ -42,13 +42,11 @@ pub(crate) struct H2Writer { written: u64, buffer: Output, buffer_capacity: usize, - settings: WorkerSettings, + settings: ServiceConfig, } impl H2Writer { - pub fn new( - respond: SendResponse, settings: WorkerSettings, - ) -> H2Writer { + pub fn new(respond: SendResponse, settings: ServiceConfig) -> H2Writer { H2Writer { stream: None, flags: Flags::empty(), diff --git a/src/server/incoming.rs b/src/server/incoming.rs index c4e984b9d..f2bc1d8f5 100644 --- a/src/server/incoming.rs +++ b/src/server/incoming.rs @@ -8,7 +8,7 @@ use tokio_io::{AsyncRead, AsyncWrite}; use super::channel::{HttpChannel, WrapperStream}; use super::handler::{HttpHandler, IntoHttpHandler}; use super::http::HttpServer; -use super::settings::{ServerSettings, WorkerSettings}; +use super::settings::{ServerSettings, ServiceConfig}; impl Message for WrapperStream { type Result = (); @@ -32,7 +32,7 @@ where // set server settings let addr: net::SocketAddr = "127.0.0.1:8080".parse().unwrap(); let apps = (self.factory)().into_handler(); - let settings = WorkerSettings::new( + let settings = ServiceConfig::new( apps, self.keep_alive, self.client_timeout, @@ -49,7 +49,7 @@ where } struct HttpIncoming { - settings: WorkerSettings, + settings: ServiceConfig, } impl Actor for HttpIncoming { diff --git a/src/server/mod.rs b/src/server/mod.rs index 456b46183..d6e9f26b1 100644 --- a/src/server/mod.rs +++ b/src/server/mod.rs @@ -143,7 +143,7 @@ pub use self::message::Request; pub use self::ssl::*; pub use self::error::{AcceptorError, HttpDispatchError}; -pub use self::settings::{ServerSettings, WorkerSettings, WorkerSettingsBuilder}; +pub use self::settings::{ServerSettings, ServiceConfig, ServiceConfigBuilder}; #[doc(hidden)] pub use self::service::{HttpService, StreamConfiguration}; diff --git a/src/server/service.rs b/src/server/service.rs index 231ac599e..ec71a1f1f 100644 --- a/src/server/service.rs +++ b/src/server/service.rs @@ -8,7 +8,7 @@ use futures::{Async, Poll}; use super::channel::HttpChannel; use super::error::HttpDispatchError; use super::handler::HttpHandler; -use super::settings::WorkerSettings; +use super::settings::ServiceConfig; use super::IoStream; /// `NewService` implementation for HTTP1/HTTP2 transports @@ -17,7 +17,7 @@ where H: HttpHandler, Io: IoStream, { - settings: WorkerSettings, + settings: ServiceConfig, _t: PhantomData, } @@ -27,7 +27,7 @@ where Io: IoStream, { /// Create new `HttpService` instance. - pub fn new(settings: WorkerSettings) -> Self { + pub fn new(settings: ServiceConfig) -> Self { HttpService { settings, _t: PhantomData, @@ -57,7 +57,7 @@ where H: HttpHandler, Io: IoStream, { - settings: WorkerSettings, + settings: ServiceConfig, _t: PhantomData, } @@ -66,7 +66,7 @@ where H: HttpHandler, Io: IoStream, { - fn new(settings: WorkerSettings) -> HttpServiceHandler { + fn new(settings: ServiceConfig) -> HttpServiceHandler { HttpServiceHandler { settings, _t: PhantomData, @@ -103,6 +103,12 @@ pub struct StreamConfiguration { _t: PhantomData<(T, E)>, } +impl Default for StreamConfiguration { + fn default() -> Self { + Self::new() + } +} + impl StreamConfiguration { /// Create new `StreamConfigurationService` instance. pub fn new() -> Self { @@ -136,8 +142,8 @@ impl NewService for StreamConfiguration { fn new_service(&self) -> Self::Future { ok(StreamConfigurationService { - no_delay: self.no_delay.clone(), - tcp_ka: self.tcp_ka.clone(), + no_delay: self.no_delay, + tcp_ka: self.tcp_ka, _t: PhantomData, }) } diff --git a/src/server/settings.rs b/src/server/settings.rs index 2f306073c..3798fae50 100644 --- a/src/server/settings.rs +++ b/src/server/settings.rs @@ -127,7 +127,8 @@ impl ServerSettings { // "Sun, 06 Nov 1994 08:49:37 GMT".len() const DATE_VALUE_LENGTH: usize = 29; -pub struct WorkerSettings(Rc>); +/// Http service configuration +pub struct ServiceConfig(Rc>); struct Inner { handler: H, @@ -141,18 +142,18 @@ struct Inner { date: UnsafeCell<(bool, Date)>, } -impl Clone for WorkerSettings { +impl Clone for ServiceConfig { fn clone(&self) -> Self { - WorkerSettings(self.0.clone()) + ServiceConfig(self.0.clone()) } } -impl WorkerSettings { - /// Create instance of `WorkerSettings` +impl ServiceConfig { + /// Create instance of `ServiceConfig` pub(crate) fn new( handler: H, keep_alive: KeepAlive, client_timeout: u64, client_shutdown: u64, settings: ServerSettings, - ) -> WorkerSettings { + ) -> ServiceConfig { let (keep_alive, ka_enabled) = match keep_alive { KeepAlive::Timeout(val) => (val as u64, true), KeepAlive::Os | KeepAlive::Tcp(_) => (0, true), @@ -164,7 +165,7 @@ impl WorkerSettings { None }; - WorkerSettings(Rc::new(Inner { + ServiceConfig(Rc::new(Inner { handler, keep_alive, ka_enabled, @@ -178,8 +179,8 @@ impl WorkerSettings { } /// Create worker settings builder. - pub fn build(handler: H) -> WorkerSettingsBuilder { - WorkerSettingsBuilder::new(handler) + pub fn build(handler: H) -> ServiceConfigBuilder { + ServiceConfigBuilder::new(handler) } pub(crate) fn head(&self) -> RefMut> { @@ -220,7 +221,7 @@ impl WorkerSettings { } } -impl WorkerSettings { +impl ServiceConfig { #[inline] /// Client timeout for first request. pub fn client_timer(&self) -> Option { @@ -319,11 +320,11 @@ impl WorkerSettings { } } -/// An worker settings builder +/// A service config builder /// -/// This type can be used to construct an instance of `WorkerSettings` through a +/// This type can be used to construct an instance of `ServiceConfig` through a /// builder-like pattern. -pub struct WorkerSettingsBuilder { +pub struct ServiceConfigBuilder { handler: H, keep_alive: KeepAlive, client_timeout: u64, @@ -333,10 +334,10 @@ pub struct WorkerSettingsBuilder { secure: bool, } -impl WorkerSettingsBuilder { - /// Create instance of `WorkerSettingsBuilder` - pub fn new(handler: H) -> WorkerSettingsBuilder { - WorkerSettingsBuilder { +impl ServiceConfigBuilder { + /// Create instance of `ServiceConfigBuilder` + pub fn new(handler: H) -> ServiceConfigBuilder { + ServiceConfigBuilder { handler, keep_alive: KeepAlive::Timeout(5), client_timeout: 5000, @@ -419,12 +420,12 @@ impl WorkerSettingsBuilder { self } - /// Finish worker settings configuration and create `WorkerSettings` object. - pub fn finish(self) -> WorkerSettings { + /// Finish service configuration and create `ServiceConfig` object. + pub fn finish(self) -> ServiceConfig { let settings = ServerSettings::new(self.addr, &self.host, self.secure); let client_shutdown = if self.secure { self.client_shutdown } else { 0 }; - WorkerSettings::new( + ServiceConfig::new( self.handler, self.keep_alive, self.client_timeout, @@ -507,7 +508,7 @@ mod tests { let mut rt = current_thread::Runtime::new().unwrap(); let _ = rt.block_on(future::lazy(|| { - let settings = WorkerSettings::<()>::new( + let settings = ServiceConfig::<()>::new( (), KeepAlive::Os, 0, diff --git a/tests/test_server.rs b/tests/test_server.rs index 240a5ddc0..8d9a400d8 100644 --- a/tests/test_server.rs +++ b/tests/test_server.rs @@ -1228,7 +1228,7 @@ fn test_custom_pipeline() { use actix::System; use actix_net::service::NewServiceExt; use actix_web::server::{ - HttpService, KeepAlive, StreamConfiguration, WorkerSettings, + HttpService, KeepAlive, ServiceConfig, StreamConfiguration, }; let addr = test::TestServer::unused_addr(); @@ -1239,7 +1239,7 @@ fn test_custom_pipeline() { let app = App::new() .route("/", http::Method::GET, |_: HttpRequest| "OK") .finish(); - let settings = WorkerSettings::build(app) + let settings = ServiceConfig::build(app) .keep_alive(KeepAlive::Disabled) .client_timeout(1000) .client_shutdown(1000)