This commit is contained in:
nora 2023-03-07 16:55:48 +01:00
parent dd3b3980bf
commit b4e7136ad9
9 changed files with 93 additions and 271 deletions

View file

@ -3,22 +3,22 @@ use std::fmt;
use std::time::Duration; use std::time::Duration;
use futures_util::future::{self, Either, FutureExt as _, TryFutureExt as _}; use futures_util::future::{Either};
use super::conn; use super::conn;
use super::connect::{self, sealed::Connect, Alpn, Connected, Connection}; use super::connect::{sealed::Connect, Connected};
use super::pool::{self, Key as PoolKey, Pool, Poolable, Pooled, Reservation}; use super::pool::{self, Key as PoolKey, Pool, Poolable, Reservation};
#[cfg(feature = "tcp")] #[cfg(feature = "tcp")]
use super::HttpConnector; use super::HttpConnector;
use crate::body::{Body, HttpBody}; use crate::body::{Body, HttpBody};
use crate::common::{ use crate::common::{
exec::BoxSendFuture, lazy as hyper_lazy, sync_wrapper::SyncWrapper, task, Future, Lazy, Pin, exec::BoxSendFuture, sync_wrapper::SyncWrapper, task, Future, Pin,
Poll, Poll,
}; };
use crate::rt::Executor; use crate::rt::Executor;
use http::uri::{Port, Scheme}; use http::uri::{Port, Scheme};
use http::{Request, Response, Uri, Version}; use http::{Request, Response, Uri, Version};
use tracing::{debug, trace};
#[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))] #[cfg_attr(docsrs, doc(cfg(any(feature = "http1", feature = "http2"))))]
pub struct Client<C, B = Body> { pub struct Client<C, B = Body> {

View file

@ -1,5 +1,4 @@
#[cfg(all(feature = "server", any(feature = "http1", feature = "http2")))]
use crate::body::Body;
#[cfg(feature = "server")] #[cfg(feature = "server")]
use crate::body::HttpBody; use crate::body::HttpBody;
#[cfg(all(feature = "http2", feature = "server"))] #[cfg(all(feature = "http2", feature = "server"))]

View file

@ -16,42 +16,42 @@ struct ErrorImpl {
pub(super) enum Kind { pub(super) enum Kind {
Parse(Parse), Parse(Parse),
User(User), User(User),
#[allow(unused)] #[allow(unused)]
IncompleteMessage, IncompleteMessage,
#[cfg(feature = "http1")] #[cfg(feature = "http1")]
UnexpectedMessage, UnexpectedMessage,
Canceled, Canceled,
ChannelClosed, ChannelClosed,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
Io, Io,
#[allow(unused)] #[allow(unused)]
Connect, Connect,
#[cfg(all(feature = "tcp", feature = "server"))] #[cfg(all(feature = "tcp", feature = "server"))]
Listen, Listen,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
#[cfg(feature = "server")] #[cfg(feature = "server")]
Accept, Accept,
#[cfg(all(feature = "http1", feature = "server", feature = "runtime"))] #[cfg(all(feature = "http1", feature = "server", feature = "runtime"))]
HeaderTimeout, HeaderTimeout,
#[cfg(any(feature = "http1", feature = "http2", feature = "stream"))] #[cfg(any(feature = "http1", feature = "http2", feature = "stream"))]
Body, Body,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
BodyWrite, BodyWrite,
#[cfg(feature = "http1")] #[cfg(feature = "http1")]
Shutdown, Shutdown,
#[cfg(feature = "http2")] #[cfg(feature = "http2")]
Http2, Http2,
} }
@ -82,100 +82,95 @@ pub(super) enum Header {
} }
#[derive(Debug)] #[derive(Debug)]
pub(super) enum User { pub(super) enum User {
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
Body, Body,
BodyWriteAborted, BodyWriteAborted,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
#[cfg(feature = "server")] #[cfg(feature = "server")]
MakeService, MakeService,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
Service, Service,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
#[cfg(feature = "server")] #[cfg(feature = "server")]
UnexpectedHeader, UnexpectedHeader,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
#[cfg(feature = "client")] #[cfg(feature = "client")]
UnsupportedVersion, UnsupportedVersion,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
#[cfg(feature = "client")] #[cfg(feature = "client")]
UnsupportedRequestMethod, UnsupportedRequestMethod,
#[cfg(feature = "http1")] #[cfg(feature = "http1")]
#[cfg(feature = "server")] #[cfg(feature = "server")]
UnsupportedStatusCode, UnsupportedStatusCode,
#[cfg(any(feature = "http1", feature = "http2"))] #[cfg(any(feature = "http1", feature = "http2"))]
#[cfg(feature = "client")] #[cfg(feature = "client")]
AbsoluteUriRequired, AbsoluteUriRequired,
NoUpgrade, NoUpgrade,
#[cfg(feature = "http1")] #[cfg(feature = "http1")]
ManualUpgrade, ManualUpgrade,
#[cfg(feature = "server")] #[cfg(feature = "server")]
WithoutShutdownNonHttp1, WithoutShutdownNonHttp1,
#[cfg(feature = "client")] #[cfg(feature = "client")]
DispatchGone, DispatchGone,
#[cfg(feature = "ffi")] #[cfg(feature = "ffi")]
AbortedByCallback, AbortedByCallback,
} }
#[derive(Debug)] #[derive(Debug)]
pub(super) struct TimedOut; pub(super) struct TimedOut;
impl Error { impl Error {
pub(crate) fn is_parse(&self) -> bool { pub(crate) fn is_parse(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_parse_too_large(&self) -> bool { pub(crate) fn is_parse_too_large(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_parse_status(&self) -> bool { pub(crate) fn is_parse_status(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_user(&self) -> bool { pub(crate) fn is_user(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_canceled(&self) -> bool { pub(crate) fn is_canceled(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_closed(&self) -> bool { pub(crate) fn is_closed(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_connect(&self) -> bool { pub(crate) fn is_connect(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_incomplete_message(&self) -> bool { pub(crate) fn is_incomplete_message(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_body_write_aborted(&self) -> bool { pub(crate) fn is_body_write_aborted(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn is_timeout(&self) -> bool { pub(crate) fn is_timeout(&self) -> bool {
loop {} loop {}
} }
pub(crate) fn into_cause(self) -> Option<Box<dyn StdError + Send + Sync>> { pub(crate) fn into_cause(self) -> Option<Box<dyn StdError + Send + Sync>> {
loop {} loop {}
} }
@ -319,7 +314,7 @@ impl Error {
pub(super) fn new_h2(cause: ::h2::Error) -> Error { pub(super) fn new_h2(cause: ::h2::Error) -> Error {
loop {} loop {}
} }
pub(crate) fn message(&self) -> impl fmt::Display + '_ { pub(crate) fn message(&self) -> impl fmt::Display + '_ {
self.description() self.description()
} }

View file

@ -13,21 +13,16 @@ use std::fmt;
mod h1_reason_phrase; mod h1_reason_phrase;
#[cfg(feature = "http2")] #[cfg(feature = "http2")]
#[derive(Clone, Eq, PartialEq)] #[derive(Clone, Eq, PartialEq)]
pub(crate) struct Protocol { pub(crate) struct Protocol {
inner: h2::ext::Protocol, inner: h2::ext::Protocol,
} }
#[cfg(feature = "http2")] #[cfg(feature = "http2")]
impl Protocol { impl Protocol {
pub(crate) const fn from_static(value: &'static str) -> Self { pub(crate) const fn from_static(value: &'static str) -> Self {
loop {} loop {}
} }
pub(crate) fn as_str(&self) -> &str { pub(crate) fn as_str(&self) -> &str {
loop {} loop {}
} }
@ -57,45 +52,19 @@ impl fmt::Debug for Protocol {
loop {} loop {}
} }
} }
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct HeaderCaseMap(HeaderMap<Bytes>); pub(crate) struct HeaderCaseMap(HeaderMap<Bytes>);
#[cfg(feature = "http1")] #[cfg(feature = "http1")]
impl HeaderCaseMap { impl HeaderCaseMap {
pub(crate) fn get_all<'a>( pub(crate) fn get_all<'a>(
&'a self, &'a self,
name: &HeaderName, name: &HeaderName,
) -> impl Iterator<Item = impl AsRef<[u8]> + 'a> + 'a { ) -> impl Iterator<Item = impl AsRef<[u8]> + 'a> + 'a {
self.get_all_internal(name).into_iter() self.get_all_internal(name).into_iter()
} }
pub(crate) fn get_all_internal<'a>(&'a self, name: &HeaderName) -> ValueIter<'_, Bytes> {
pub(crate) fn get_all_internal<'a>(
&'a self,
name: &HeaderName,
) -> ValueIter<'_, Bytes> {
loop {} loop {}
} }
pub(crate) fn default() -> Self { pub(crate) fn default() -> Self {
@ -116,14 +85,8 @@ impl HeaderCaseMap {
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) struct OriginalHeaderOrder { pub(crate) struct OriginalHeaderOrder {
num_entries: HashMap<HeaderName, usize>, num_entries: HashMap<HeaderName, usize>,
entry_order: Vec<(HeaderName, usize)>, entry_order: Vec<(HeaderName, usize)>,
} }
#[cfg(all(feature = "http1", feature = "ffi"))] #[cfg(all(feature = "http1", feature = "ffi"))]
@ -140,43 +103,7 @@ impl OriginalHeaderOrder {
{ {
loop {} loop {}
} }
pub(crate) fn get_in_order(&self) -> impl Iterator<Item = &(HeaderName, usize)> { pub(crate) fn get_in_order(&self) -> impl Iterator<Item = &(HeaderName, usize)> {
loop {} loop {}
} }

View file

@ -1,2 +1,2 @@
use std::convert::TryFrom;
use bytes::Bytes;

View file

@ -1,57 +1,4 @@
use http::header::{HeaderValue, ValueIter}; use http::header::{HeaderValue, ValueIter};
use http::HeaderMap; use http::HeaderMap;
#[cfg(all(feature = "http2", feature = "client"))] #[cfg(all(feature = "http2", feature = "client"))]
use http::Method; use http::Method;
#[cfg(feature = "http1")]
pub(super) fn connection_keep_alive(value: &HeaderValue) -> bool {
loop {}
}
#[cfg(feature = "http1")]
pub(super) fn connection_close(value: &HeaderValue) -> bool {
loop {}
}
#[cfg(feature = "http1")]
fn connection_has(value: &HeaderValue, needle: &str) -> bool {
loop {}
}
#[cfg(all(feature = "http1", feature = "server"))]
pub(super) fn content_length_parse(value: &HeaderValue) -> Option<u64> {
loop {}
}
pub(super) fn content_length_parse_all(headers: &HeaderMap) -> Option<u64> {
loop {}
}
pub(super) fn content_length_parse_all_values(
values: ValueIter<'_, HeaderValue>,
) -> Option<u64> {
loop {}
}
fn from_digits(bytes: &[u8]) -> Option<u64> {
loop {}
}
#[cfg(all(feature = "http2", feature = "client"))]
pub(super) fn method_has_defined_payload_semantics(method: &Method) -> bool {
loop {}
}
#[cfg(feature = "http2")]
pub(super) fn set_content_length_if_missing(headers: &mut HeaderMap, len: u64) {
loop {}
}
#[cfg(feature = "http1")]
pub(super) fn transfer_encoding_is_chunked(headers: &HeaderMap) -> bool {
loop {}
}
#[cfg(feature = "http1")]
pub(super) fn is_chunked(mut encodings: ValueIter<'_, HeaderValue>) -> bool {
loop {}
}
#[cfg(feature = "http1")]
pub(super) fn is_chunked_(value: &HeaderValue) -> bool {
loop {}
}
#[cfg(feature = "http1")]
pub(super) fn add_chunked(mut entry: http::header::OccupiedEntry<'_, HeaderValue>) {
loop {}
}

View file

@ -3,15 +3,14 @@ use super::accept::Accept;
use super::conn::Http as Http_; use super::conn::Http as Http_;
#[cfg(all(feature = "tcp"))] #[cfg(all(feature = "tcp"))]
use super::tcp::AddrIncoming; use super::tcp::AddrIncoming;
use crate::body::{Body, HttpBody}; use crate::body::{Body};
use crate::common::exec::Exec; use crate::common::exec::Exec;
use crate::common::exec::{ConnStreamExec, NewSvcExec}; use crate::common::exec::{NewSvcExec};
use crate::common::{task, Future, Pin, Poll, Unpin}; use crate::common::{task, Future, Pin, Poll};
use crate::service::{HttpService, MakeServiceRef}; use crate::service::{HttpService, MakeServiceRef};
use pin_project_lite::pin_project; use pin_project_lite::pin_project;
use std::error::Error as StdError; use std::error::Error as StdError;
#[cfg(feature = "tcp")]
use tokio::io::{AsyncRead, AsyncWrite};
pub struct Server<I, S, E = Exec> { pub struct Server<I, S, E = Exec> {
incoming: I, incoming: I,
make_service: S, make_service: S,
@ -91,7 +90,7 @@ where
} }
pub(crate) mod new_svc { pub(crate) mod new_svc {
use super::Watcher; use super::Watcher;
use crate::body::{Body, HttpBody}; use crate::body::{Body};
use crate::common::exec::ConnStreamExec; use crate::common::exec::ConnStreamExec;
use crate::common::{task, Future, Pin, Poll}; use crate::common::{task, Future, Pin, Poll};
use crate::service::HttpService; use crate::service::HttpService;

View file

@ -1,14 +1,14 @@
use std::fmt; use std::fmt;
use std::io; use std::io;
use std::net::{SocketAddr, TcpListener as StdTcpListener}; use std::net::SocketAddr;
use std::time::Duration; use std::time::Duration;
use socket2::TcpKeepalive;
use tokio::net::TcpListener;
use tokio::time::Sleep;
use crate::common::{task, Pin, Poll};
#[allow(unreachable_pub)] #[allow(unreachable_pub)]
pub use self::addr_stream::AddrStream; pub use self::addr_stream::AddrStream;
use super::accept::Accept; use super::accept::Accept;
use crate::common::{task, Pin, Poll};
use tokio::net::TcpListener;
use tokio::time::Sleep;
#[derive(Default, Debug, Clone, Copy)] #[derive(Default, Debug, Clone, Copy)]
struct TcpKeepaliveConfig { struct TcpKeepaliveConfig {
time: Option<Duration>, time: Option<Duration>,
@ -16,62 +16,46 @@ struct TcpKeepaliveConfig {
retries: Option<u32>, retries: Option<u32>,
} }
impl TcpKeepaliveConfig { impl TcpKeepaliveConfig {
#[cfg( #[cfg(not(any(
not( target_os = "android",
any( target_os = "dragonfly",
target_os = "android", target_os = "freebsd",
target_os = "dragonfly", target_os = "fuchsia",
target_os = "freebsd", target_os = "illumos",
target_os = "fuchsia", target_os = "linux",
target_os = "illumos", target_os = "netbsd",
target_os = "linux", target_vendor = "apple",
target_os = "netbsd", windows,
target_vendor = "apple", )))]
windows,
)
)
)]
fn ka_with_interval(ka: TcpKeepalive, _: Duration, _: &mut bool) -> TcpKeepalive { fn ka_with_interval(ka: TcpKeepalive, _: Duration, _: &mut bool) -> TcpKeepalive {
loop {} loop {}
} }
#[cfg( #[cfg(not(any(
not( target_os = "android",
any( target_os = "dragonfly",
target_os = "android", target_os = "freebsd",
target_os = "dragonfly", target_os = "fuchsia",
target_os = "freebsd", target_os = "illumos",
target_os = "fuchsia", target_os = "linux",
target_os = "illumos", target_os = "netbsd",
target_os = "linux", target_vendor = "apple",
target_os = "netbsd", )))]
target_vendor = "apple",
)
)
)]
fn ka_with_retries(ka: TcpKeepalive, _: u32, _: &mut bool) -> TcpKeepalive { fn ka_with_retries(ka: TcpKeepalive, _: u32, _: &mut bool) -> TcpKeepalive {
loop {} loop {}
} }
} }
#[must_use = "streams do nothing unless polled"] #[must_use = "streams do nothing unless polled"]
pub struct AddrIncoming { pub struct AddrIncoming {}
addr: SocketAddr,
listener: TcpListener,
sleep_on_errors: bool,
tcp_keepalive_config: TcpKeepaliveConfig,
tcp_nodelay: bool,
timeout: Option<Pin<Box<Sleep>>>,
}
impl AddrIncoming { impl AddrIncoming {
pub fn bind(addr: &SocketAddr) -> crate::Result<Self> { pub fn bind(addr: &SocketAddr) -> crate::Result<Self> {
loop {} loop {}
} }
pub fn local_addr(&self) -> SocketAddr { pub fn local_addr(&self) -> SocketAddr {
loop {} loop {}
} }
pub fn set_nodelay(&mut self, enabled: bool) -> &mut Self { pub fn set_nodelay(&mut self, enabled: bool) -> &mut Self {
loop {} loop {}
} }
@ -92,13 +76,13 @@ impl fmt::Debug for AddrIncoming {
} }
} }
mod addr_stream { mod addr_stream {
use crate::common::{task, Pin, Poll};
use std::io; use std::io;
use std::net::SocketAddr; use std::net::SocketAddr;
#[cfg(unix)] #[cfg(unix)]
use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::io::{AsRawFd, RawFd};
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf}; use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};
use tokio::net::TcpStream; use tokio::net::TcpStream;
use crate::common::{task, Pin, Poll};
pin_project_lite::pin_project! { pin_project_lite::pin_project! {
#[doc = " A transport returned yieled by `AddrIncoming`."] #[derive(Debug)] pub #[doc = " A transport returned yieled by `AddrIncoming`."] #[derive(Debug)] pub
struct AddrStream { #[pin] inner : TcpStream, pub (super) remote_addr : struct AddrStream { #[pin] inner : TcpStream, pub (super) remote_addr :
@ -133,17 +117,11 @@ mod addr_stream {
loop {} loop {}
} }
#[inline] #[inline]
fn poll_flush( fn poll_flush(self: Pin<&mut Self>, _cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
self: Pin<&mut Self>,
_cx: &mut task::Context<'_>,
) -> Poll<io::Result<()>> {
loop {} loop {}
} }
#[inline] #[inline]
fn poll_shutdown( fn poll_shutdown(self: Pin<&mut Self>, cx: &mut task::Context<'_>) -> Poll<io::Result<()>> {
self: Pin<&mut Self>,
cx: &mut task::Context<'_>,
) -> Poll<io::Result<()>> {
loop {} loop {}
} }
#[inline] #[inline]

View file

@ -1,26 +1,9 @@
use std::error::Error as StdError;
use std::fmt;
use std::marker::PhantomData;
use crate::body::HttpBody; use crate::body::HttpBody;
use crate::common::{task, Future, Poll}; use crate::common::{task, Future, Poll};
use crate::{Request, Response}; use crate::{Request, Response};
use std::error::Error as StdError;
use std::fmt;
use std::marker::PhantomData;
pub fn service_fn<F, R, S>(f: F) -> ServiceFn<F, R> pub fn service_fn<F, R, S>(f: F) -> ServiceFn<F, R>
where where
@ -35,7 +18,7 @@ pub struct ServiceFn<F, R> {
_req: PhantomData<fn(R)>, _req: PhantomData<fn(R)>,
} }
impl<F, ReqBody, Ret, ResBody, E> tower_service::Service<crate::Request<ReqBody>> impl<F, ReqBody, Ret, ResBody, E> tower_service::Service<crate::Request<ReqBody>>
for ServiceFn<F, ReqBody> for ServiceFn<F, ReqBody>
where where
F: FnMut(Request<ReqBody>) -> Ret, F: FnMut(Request<ReqBody>) -> Ret,
ReqBody: HttpBody, ReqBody: HttpBody,
@ -46,10 +29,7 @@ where
type Response = crate::Response<ResBody>; type Response = crate::Response<ResBody>;
type Error = E; type Error = E;
type Future = Ret; type Future = Ret;
fn poll_ready( fn poll_ready(&mut self, _cx: &mut task::Context<'_>) -> Poll<Result<(), Self::Error>> {
&mut self,
_cx: &mut task::Context<'_>,
) -> Poll<Result<(), Self::Error>> {
loop {} loop {}
} }
fn call(&mut self, req: Request<ReqBody>) -> Self::Future { fn call(&mut self, req: Request<ReqBody>) -> Self::Future {
@ -69,7 +49,4 @@ where
loop {} loop {}
} }
} }
impl<F, R> Copy for ServiceFn<F, R> impl<F, R> Copy for ServiceFn<F, R> where F: Copy {}
where
F: Copy,
{}