diff --git a/hyper/src/server/server.rs b/hyper/src/server/server.rs index 33c4598..de00c82 100644 --- a/hyper/src/server/server.rs +++ b/hyper/src/server/server.rs @@ -1,18 +1,17 @@ -use std::error::Error as StdError; -#[cfg(feature = "tcp")] -use std::net::{SocketAddr, TcpListener as StdTcpListener}; -use pin_project_lite::pin_project; -use tokio::io::{AsyncRead, AsyncWrite}; +use self::new_svc::NewSvcTask; use super::accept::Accept; +use super::conn::Http as Http_; #[cfg(all(feature = "tcp"))] use super::tcp::AddrIncoming; use crate::body::{Body, HttpBody}; use crate::common::exec::Exec; use crate::common::exec::{ConnStreamExec, NewSvcExec}; use crate::common::{task, Future, Pin, Poll, Unpin}; -use super::conn::{Http as Http_, UpgradeableConnection}; use crate::service::{HttpService, MakeServiceRef}; -use self::new_svc::NewSvcTask; +use pin_project_lite::pin_project; +use std::error::Error as StdError; +#[cfg(feature = "tcp")] +use tokio::io::{AsyncRead, AsyncWrite}; pin_project! { #[doc = " A listening HTTP server that accepts connections in both HTTP1 and HTTP2 by default."] @@ -21,9 +20,9 @@ pin_project! { " handlers. It is built using the [`Builder`](Builder), and the future"] #[doc = " completes when the server has been shutdown. It should be run by an"] #[doc = " `Executor`."] - + pub struct Server < I, S, E = Exec > { - + #[pin] incoming : I, make_service : S, protocol : Http_ < E >, @@ -38,7 +37,6 @@ pub struct Builder { } #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] impl Server { - pub fn builder(incoming: I) -> Builder { loop {} } @@ -49,72 +47,12 @@ impl Server { doc(cfg(all(feature = "tcp", any(feature = "http1", feature = "http2")))) )] impl Server { - - - - - - pub fn bind() -> Builder { loop {} } } -#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] -impl Server -where - I: Accept, - IE: Into>, - IO: AsyncRead + AsyncWrite + Unpin + Send + 'static, - S: MakeServiceRef, - S::Error: Into>, - B: HttpBody + 'static, - B::Error: Into>, - E: ConnStreamExec<>::Future, B>, -{ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - fn poll_next_( - self: Pin<&mut Self>, - cx: &mut task::Context<'_>, - ) -> Poll>>> { - loop {} - } -} + #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] impl Future for Server where @@ -131,12 +69,8 @@ where type Output = crate::Result<()>; fn poll(mut self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll { loop { - if let Some(connecting) = ready!(self.as_mut().poll_next_(cx) ?) { - let fut = NewSvcTask::new(connecting, NoopWatcher); - self.as_mut().project().protocol.exec.execute_new_svc(fut); - } else { - loop {} - } + let fut = NewSvcTask::new(NoopWatcher); + self.as_mut().project().protocol.exec.execute_new_svc(fut); } } } @@ -148,7 +82,6 @@ impl Builder { loop {} } - pub fn serve(self, _: S) -> Server where I: Accept, @@ -174,38 +107,38 @@ where } } pub(crate) mod new_svc { - use std::error::Error as StdError; - use tokio::io::{AsyncRead, AsyncWrite}; use super::{Connecting, Watcher}; use crate::body::{Body, HttpBody}; use crate::common::exec::ConnStreamExec; use crate::common::{task, Future, Pin, Poll, Unpin}; use crate::service::HttpService; use pin_project_lite::pin_project; + use std::error::Error as StdError; + use tokio::io::{AsyncRead, AsyncWrite}; pin_project! { - #[allow(missing_debug_implementations)] - + #[allow(missing_debug_implementations)] + pub struct NewSvcTask < I, N, S, E, W : Watcher < I, S, E >> { - - #[pin] + + #[pin] state : State , a: (N) - + } } pin_project! { #[project = StateProj] - + pub (super) enum State > { - + Connecting { a: (I, S, W, E), }, - + Connected { #[pin] future : W::Future, }, } } impl, E, W: Watcher> NewSvcTask { - pub(super) fn new(connecting: Connecting, watcher: W) -> Self { + pub(super) fn new(watcher: W) -> Self { loop {} } } @@ -230,7 +163,13 @@ pin_project! { #[doc = " A future building a new `Service` to a `Connection`."] #[doc = ""] #[doc = " Wraps the future returned from `MakeService` into one that returns"] #[doc = " a `Connection`."] #[must_use = "futures do nothing unless polled"] #[derive(Debug)] - #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] pub struct - Connecting < I, F, E = Exec > { #[pin] future : F, io : Option < I >, protocol : - Http_ < E >, } + #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] + + pub struct Connecting < F, E = Exec > { + + #[pin] future : F, + protocol : + Http_ < E >, + + } } diff --git a/warp/src/server.rs b/warp/src/server.rs index 1be1777..099faa4 100644 --- a/warp/src/server.rs +++ b/warp/src/server.rs @@ -1,21 +1,21 @@ +use crate::filter::Filter; +use crate::reject::IsReject; +use crate::reply::Reply; #[cfg(feature = "tls")] use crate::tls::TlsConfigBuilder; +use crate::transport::Transport; +use futures_util::{future, FutureExt, TryFuture, TryStream, TryStreamExt}; +use hyper::server::conn::AddrIncoming; +use hyper::service::{make_service_fn, service_fn}; +use hyper::Server as HyperServer; use std::convert::Infallible; use std::error::Error as StdError; use std::future::Future; use std::net::SocketAddr; #[cfg(feature = "tls")] use std::path::Path; -use futures_util::{future, FutureExt, TryFuture, TryStream, TryStreamExt}; -use hyper::server::conn::AddrIncoming; -use hyper::service::{make_service_fn, service_fn}; -use hyper::Server as HyperServer; use tokio::io::{AsyncRead, AsyncWrite}; use tracing::Instrument; -use crate::filter::Filter; -use crate::reject::IsReject; -use crate::reply::Reply; -use crate::transport::Transport; pub fn serve(filter: F) -> Server where @@ -32,74 +32,22 @@ pub struct Server { filter: F, } - - #[cfg(feature = "tls")] pub struct TlsServer { server: Server, tls: TlsConfigBuilder, } -macro_rules! into_service { - ($into:expr) => { - { let inner = crate ::service($into); make_service_fn(move | transport | { let - inner = inner.clone(); let remote_addr = Transport::remote_addr(transport); - future::ok::< _, Infallible > (service_fn(move | req | { inner - .call_with_addr(req, remote_addr) })) }) } - }; -} -macro_rules! addr_incoming { - ($addr:expr) => { - { let mut incoming = AddrIncoming::bind($addr) ?; incoming.set_nodelay(true); let - addr = incoming.local_addr(); (addr, incoming) } - }; -} -macro_rules! bind_inner { - ($this:ident, $addr:expr) => { - { let service = into_service!($this .filter); let (addr, incoming) = - addr_incoming!($addr); let srv = HyperServer::builder(incoming) - .http1_pipeline_flush($this .pipeline).serve(service); Ok::< _, hyper::Error > - ((addr, srv)) } - }; - (tls : $this:ident, $addr:expr) => { - { let service = into_service!($this .server.filter); let (addr, incoming) = - addr_incoming!($addr); let tls = $this .tls.build() ?; let srv = - HyperServer::builder(crate ::tls::TlsAcceptor::new(tls, incoming)) - .http1_pipeline_flush($this .server.pipeline).serve(service); Ok::< _, Box < dyn - std::error::Error + Send + Sync >> ((addr, srv)) } - }; -} -macro_rules! bind { - ($this:ident, $addr:expr) => { - { let addr = $addr .into(); (| addr | bind_inner!($this, addr)) (& addr) - .unwrap_or_else(| e | { panic!("error binding to {}: {}", addr, e); }) } - }; - (tls : $this:ident, $addr:expr) => { - { let addr = $addr .into(); (| addr | bind_inner!(tls : $this, addr)) (& addr) - .unwrap_or_else(| e | { panic!("error binding to {}: {}", addr, e); }) } - }; -} -macro_rules! try_bind { - ($this:ident, $addr:expr) => { - { (| addr | bind_inner!($this, addr)) ($addr) } - }; - (tls : $this:ident, $addr:expr) => { - { (| addr | bind_inner!(tls : $this, addr)) ($addr) } - }; -} + impl Server where F: Filter + Clone + Send + Sync + 'static, ::Ok: Reply, ::Error: IsReject, { - pub async fn run(self, addr: impl Into) { loop {} } - - - - + pub async fn run_incoming(self, incoming: I) where I: TryStream + Send, @@ -108,107 +56,22 @@ where { loop {} } - - - - - - - pub fn bind( - self, - addr: impl Into + 'static, - ) -> impl Future + 'static { - let (_, fut) = self.bind_ephemeral(addr); - fut + + pub fn bind(self, addr: impl Into + 'static) -> impl Future + 'static { + async {} } - - - - - + pub async fn try_bind(self, addr: impl Into) { loop {} } - - - - - - - - + pub fn bind_ephemeral( self, addr: impl Into, ) -> (SocketAddr, impl Future + 'static) { - let (addr, srv) = bind!(self, addr); - let srv = srv - .map(|result| { - if let Err(err) = result { - tracing::error!("server error: {}", err) - } - }); - (addr, srv) + (addr.into(), async {}) } - - - - - - - - pub fn try_bind_ephemeral( - self, - addr: impl Into, - ) -> Result<(SocketAddr, impl Future + 'static), crate::Error> { - let addr = addr.into(); - let (addr, srv) = try_bind!(self, & addr).map_err(crate::Error::new)?; - let srv = srv - .map(|result| { - if let Err(err) = result { - tracing::error!("server error: {}", err) - } - }); - Ok((addr, srv)) - } - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - pub fn serve_incoming(self, incoming: I) -> impl Future where I: TryStream + Send, @@ -219,15 +82,7 @@ where self.serve_incoming2(incoming) .instrument(tracing::info_span!("Server::serve_incoming")) } - - - - - - - - - + pub fn serve_incoming_with_graceful_shutdown( self, incoming: I, @@ -238,23 +93,7 @@ where I::Ok: AsyncRead + AsyncWrite + Send + 'static + Unpin, I::Error: Into>, { - let incoming = incoming.map_ok(crate::transport::LiftIo); - let service = into_service!(self.filter); - let pipeline = self.pipeline; - async move { - let srv = HyperServer::builder( - hyper::server::accept::from_stream(incoming.into_stream()), - ) - .http1_pipeline_flush(pipeline) - .serve(service) - .await; - if let Err(err) = srv { - tracing::error!("server error: {}", err); - } - } - .instrument( - tracing::info_span!("Server::serve_incoming_with_graceful_shutdown"), - ) + async move { loop {} } } async fn serve_incoming2(self, incoming: I) where @@ -268,9 +107,7 @@ where pub fn unstable_pipeline(mut self) -> Self { loop {} } - - - + #[cfg(feature = "tls")] pub fn tls(self) -> TlsServer { loop {} @@ -283,69 +120,38 @@ where ::Ok: Reply, ::Error: IsReject, { - - - pub fn key_path(self, path: impl AsRef) -> Self { loop {} } - - - + pub fn cert_path(self, path: impl AsRef) -> Self { loop {} } - - - - - - + pub fn client_auth_optional_path(self, path: impl AsRef) -> Self { loop {} } - - - - - - + pub fn client_auth_required_path(self, path: impl AsRef) -> Self { loop {} } - - - + pub fn key(self, key: impl AsRef<[u8]>) -> Self { loop {} } - - - + pub fn cert(self, cert: impl AsRef<[u8]>) -> Self { loop {} } - - - - - - + pub fn client_auth_optional(self, trust_anchor: impl AsRef<[u8]>) -> Self { loop {} } - - - - - - + pub fn client_auth_required(self, trust_anchor: impl AsRef<[u8]>) -> Self { loop {} } - - - + pub fn ocsp_resp(self, resp: impl AsRef<[u8]>) -> Self { loop {} } @@ -355,37 +161,22 @@ where { loop {} } - - - + pub async fn run(self, addr: impl Into) { loop {} } - - - - + pub async fn bind(self, addr: impl Into) { loop {} } - - - - - - + pub fn bind_ephemeral( self, addr: impl Into, ) -> (SocketAddr, impl Future + 'static) { loop {} } - - - - - - + pub fn bind_with_graceful_shutdown( self, addr: impl Into + 'static,