mirror of https://github.com/fafhrd91/actix-web
Merge branch 'master' into feature/h1_pending_timer
This commit is contained in:
commit
78e3ca3f00
|
@ -26,6 +26,21 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
|
# install OpenSSL on Windows
|
||||||
|
- name: Set vcpkg root
|
||||||
|
if: matrix.target.triple == 'x86_64-pc-windows-msvc'
|
||||||
|
run: echo "VCPKG_ROOT=$env:VCPKG_INSTALLATION_ROOT" | Out-File -FilePath $env:GITHUB_ENV -Append
|
||||||
|
- name: Install OpenSSL
|
||||||
|
if: matrix.target.triple == 'x86_64-pc-windows-msvc'
|
||||||
|
run: vcpkg install openssl:x64-windows
|
||||||
|
|
||||||
|
- name: Install ${{ matrix.version }}
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.version }}-${{ matrix.target.triple }}
|
||||||
|
profile: minimal
|
||||||
|
override: true
|
||||||
|
|
||||||
- name: Install ${{ matrix.version }}
|
- name: Install ${{ matrix.version }}
|
||||||
uses: actions-rs/toolchain@v1
|
uses: actions-rs/toolchain@v1
|
||||||
with:
|
with:
|
||||||
|
|
|
@ -111,12 +111,6 @@ tls-openssl = { package = "openssl", version = "0.10.9", optional = true }
|
||||||
tls-rustls = { package = "rustls", version = "0.19.0", optional = true }
|
tls-rustls = { package = "rustls", version = "0.19.0", optional = true }
|
||||||
url = "2.1"
|
url = "2.1"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.tls-openssl]
|
|
||||||
version = "0.10.9"
|
|
||||||
package = "openssl"
|
|
||||||
features = ["vendored"]
|
|
||||||
optional = true
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
brotli2 = "0.3.2"
|
brotli2 = "0.3.2"
|
||||||
criterion = "0.3"
|
criterion = "0.3"
|
||||||
|
|
|
@ -50,12 +50,6 @@ serde_urlencoded = "0.7"
|
||||||
time = { version = "0.2.23", default-features = false, features = ["std"] }
|
time = { version = "0.2.23", default-features = false, features = ["std"] }
|
||||||
tls-openssl = { version = "0.10.9", package = "openssl", optional = true }
|
tls-openssl = { version = "0.10.9", package = "openssl", optional = true }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.tls-openssl]
|
|
||||||
version = "0.10.9"
|
|
||||||
package = "openssl"
|
|
||||||
features = ["vendored"]
|
|
||||||
optional = true
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-web = { version = "4.0.0-beta.4", default-features = false, features = ["cookies"] }
|
actix-web = { version = "4.0.0-beta.4", default-features = false, features = ["cookies"] }
|
||||||
actix-http = "3.0.0-beta.4"
|
actix-http = "3.0.0-beta.4"
|
||||||
|
|
|
@ -98,11 +98,6 @@ serde_derive = "1.0"
|
||||||
tls-openssl = { version = "0.10", package = "openssl" }
|
tls-openssl = { version = "0.10", package = "openssl" }
|
||||||
tls-rustls = { version = "0.19", package = "rustls" }
|
tls-rustls = { version = "0.19", package = "rustls" }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dev-dependencies.tls-openssl]
|
|
||||||
version = "0.10.9"
|
|
||||||
package = "openssl"
|
|
||||||
features = ["vendored"]
|
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "ws"
|
name = "ws"
|
||||||
required-features = ["rustls"]
|
required-features = ["rustls"]
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::{env, io};
|
||||||
use actix_http::{Error, HttpService, Request, Response};
|
use actix_http::{Error, HttpService, Request, Response};
|
||||||
use actix_server::Server;
|
use actix_server::Server;
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt as _;
|
||||||
use http::header::HeaderValue;
|
use http::header::HeaderValue;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ use actix_http::http::HeaderValue;
|
||||||
use actix_http::{Error, HttpService, Request, Response};
|
use actix_http::{Error, HttpService, Request, Response};
|
||||||
use actix_server::Server;
|
use actix_server::Server;
|
||||||
use bytes::BytesMut;
|
use bytes::BytesMut;
|
||||||
use futures_util::StreamExt;
|
use futures_util::StreamExt as _;
|
||||||
use log::info;
|
use log::info;
|
||||||
|
|
||||||
async fn handle_request(mut req: Request) -> Result<Response, Error> {
|
async fn handle_request(mut req: Request) -> Result<Response, Error> {
|
||||||
|
|
|
@ -19,6 +19,10 @@ use super::error::SendRequestError;
|
||||||
use super::pool::Acquired;
|
use super::pool::Acquired;
|
||||||
use super::{h1proto, h2proto};
|
use super::{h1proto, h2proto};
|
||||||
|
|
||||||
|
pub trait ConnectionIo: AsyncRead + AsyncWrite + Unpin + 'static {}
|
||||||
|
|
||||||
|
impl<T: AsyncRead + AsyncWrite + Unpin + 'static> ConnectionIo for T {}
|
||||||
|
|
||||||
pub(crate) enum ConnectionType<Io> {
|
pub(crate) enum ConnectionType<Io> {
|
||||||
H1(Io),
|
H1(Io),
|
||||||
H2(H2Connection),
|
H2(H2Connection),
|
||||||
|
|
|
@ -18,7 +18,7 @@ use futures_core::ready;
|
||||||
use http::Uri;
|
use http::Uri;
|
||||||
|
|
||||||
use super::config::ConnectorConfig;
|
use super::config::ConnectorConfig;
|
||||||
use super::connection::{Connection, EitherIoConnection};
|
use super::connection::{Connection, ConnectionIo, EitherIoConnection};
|
||||||
use super::error::ConnectError;
|
use super::error::ConnectError;
|
||||||
use super::pool::ConnectionPool;
|
use super::pool::ConnectionPool;
|
||||||
use super::Connect;
|
use super::Connect;
|
||||||
|
@ -61,9 +61,6 @@ pub struct Connector<T> {
|
||||||
ssl: SslConnector,
|
ssl: SslConnector,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Io: AsyncRead + AsyncWrite + Unpin {}
|
|
||||||
impl<T: AsyncRead + AsyncWrite + Unpin> Io for T {}
|
|
||||||
|
|
||||||
impl Connector<()> {
|
impl Connector<()> {
|
||||||
#[allow(clippy::new_ret_no_self, clippy::let_unit_value)]
|
#[allow(clippy::new_ret_no_self, clippy::let_unit_value)]
|
||||||
pub fn new() -> Connector<
|
pub fn new() -> Connector<
|
||||||
|
@ -281,16 +278,16 @@ where
|
||||||
pub type DummyService = Box<
|
pub type DummyService = Box<
|
||||||
dyn Service<
|
dyn Service<
|
||||||
Connect,
|
Connect,
|
||||||
Response = (Box<dyn Io>, Protocol),
|
Response = (Box<dyn ConnectionIo>, Protocol),
|
||||||
Error = ConnectError,
|
Error = ConnectError,
|
||||||
Future = futures_core::future::LocalBoxFuture<
|
Future = futures_core::future::LocalBoxFuture<
|
||||||
'static,
|
'static,
|
||||||
Result<(Box<dyn Io>, Protocol), ConnectError>,
|
Result<(Box<dyn ConnectionIo>, Protocol), ConnectError>,
|
||||||
>,
|
>,
|
||||||
>,
|
>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
InnerConnector::<_, DummyService, _, Box<dyn Io>> {
|
InnerConnector::<_, DummyService, _, Box<dyn ConnectionIo>> {
|
||||||
tcp_pool: ConnectionPool::new(
|
tcp_pool: ConnectionPool::new(
|
||||||
tcp_service,
|
tcp_service,
|
||||||
self.config.no_disconnect_timeout(),
|
self.config.no_disconnect_timeout(),
|
||||||
|
@ -334,9 +331,12 @@ where
|
||||||
.map(|protos| protos.windows(2).any(|w| w == H2))
|
.map(|protos| protos.windows(2).any(|w| w == H2))
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
if h2 {
|
if h2 {
|
||||||
(Box::new(sock) as Box<dyn Io>, Protocol::Http2)
|
(
|
||||||
|
Box::new(sock) as Box<dyn ConnectionIo>,
|
||||||
|
Protocol::Http2,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
(Box::new(sock) as Box<dyn Io>, Protocol::Http1)
|
(Box::new(sock) as _, Protocol::Http1)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.map_err(ConnectError::from),
|
.map_err(ConnectError::from),
|
||||||
|
@ -354,9 +354,9 @@ where
|
||||||
.map(|protos| protos.windows(2).any(|w| w == H2))
|
.map(|protos| protos.windows(2).any(|w| w == H2))
|
||||||
.unwrap_or(false);
|
.unwrap_or(false);
|
||||||
if h2 {
|
if h2 {
|
||||||
(Box::new(sock) as Box<dyn Io>, Protocol::Http2)
|
(Box::new(sock) as _, Protocol::Http2)
|
||||||
} else {
|
} else {
|
||||||
(Box::new(sock) as Box<dyn Io>, Protocol::Http1)
|
(Box::new(sock) as _, Protocol::Http1)
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|
|
@ -7,7 +7,7 @@ use actix_codec::{AsyncRead, AsyncWrite, Framed, ReadBuf};
|
||||||
use bytes::buf::BufMut;
|
use bytes::buf::BufMut;
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures_core::Stream;
|
use futures_core::Stream;
|
||||||
use futures_util::{future::poll_fn, SinkExt};
|
use futures_util::{future::poll_fn, SinkExt as _};
|
||||||
|
|
||||||
use crate::error::PayloadError;
|
use crate::error::PayloadError;
|
||||||
use crate::h1;
|
use crate::h1;
|
||||||
|
@ -198,7 +198,7 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SinkExt::flush(framed.get_mut()).await?;
|
framed.get_mut().flush().await?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ pub use actix_tls::connect::{
|
||||||
Connect as TcpConnect, ConnectError as TcpConnectError, Connection as TcpConnection,
|
Connect as TcpConnect, ConnectError as TcpConnectError, Connection as TcpConnection,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub use self::connection::Connection;
|
pub use self::connection::{Connection, ConnectionIo};
|
||||||
pub use self::connector::Connector;
|
pub use self::connector::Connector;
|
||||||
pub use self::error::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
|
pub use self::error::{ConnectError, FreezeRequestError, InvalidUrl, SendRequestError};
|
||||||
pub use crate::Protocol;
|
pub use crate::Protocol;
|
||||||
|
|
|
@ -5,8 +5,10 @@ use actix_codec::{AsyncRead, AsyncWrite};
|
||||||
use actix_service::Service;
|
use actix_service::Service;
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use h2::server::{Connection, SendResponse};
|
use h2::{
|
||||||
use h2::SendStream;
|
server::{Connection, SendResponse},
|
||||||
|
SendStream,
|
||||||
|
};
|
||||||
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
|
use http::header::{HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRANSFER_ENCODING};
|
||||||
use log::{error, trace};
|
use log::{error, trace};
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ use actix_service::{
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::ready;
|
use futures_core::ready;
|
||||||
use futures_util::future::ok;
|
use futures_util::future::ok;
|
||||||
use h2::server::{self, Handshake};
|
use h2::server::{handshake, Handshake};
|
||||||
use log::error;
|
use log::error;
|
||||||
|
|
||||||
use crate::body::MessageBody;
|
use crate::body::MessageBody;
|
||||||
|
@ -307,7 +307,7 @@ where
|
||||||
Some(self.cfg.clone()),
|
Some(self.cfg.clone()),
|
||||||
addr,
|
addr,
|
||||||
on_connect_data,
|
on_connect_data,
|
||||||
server::handshake(io),
|
handshake(io),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,19 @@
|
||||||
use std::marker::PhantomData;
|
use std::{
|
||||||
use std::pin::Pin;
|
fmt,
|
||||||
use std::task::{Context, Poll};
|
future::Future,
|
||||||
use std::{fmt, net, rc::Rc};
|
marker::PhantomData,
|
||||||
|
net,
|
||||||
|
pin::Pin,
|
||||||
|
rc::Rc,
|
||||||
|
task::{Context, Poll},
|
||||||
|
};
|
||||||
|
|
||||||
use actix_codec::Framed;
|
use actix_codec::Framed;
|
||||||
use actix_rt::net::{ActixStream, TcpStream};
|
use actix_rt::net::{ActixStream, TcpStream};
|
||||||
use actix_service::{pipeline_factory, IntoServiceFactory, Service, ServiceFactory};
|
use actix_service::{pipeline_factory, IntoServiceFactory, Service, ServiceFactory};
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_core::{ready, Future};
|
use futures_core::ready;
|
||||||
use h2::server::{self, Handshake};
|
use h2::server::{handshake, Handshake};
|
||||||
use pin_project::pin_project;
|
use pin_project::pin_project;
|
||||||
|
|
||||||
use crate::body::MessageBody;
|
use crate::body::MessageBody;
|
||||||
|
@ -562,7 +567,7 @@ where
|
||||||
match proto {
|
match proto {
|
||||||
Protocol::Http2 => HttpServiceHandlerResponse {
|
Protocol::Http2 => HttpServiceHandlerResponse {
|
||||||
state: State::H2Handshake(Some((
|
state: State::H2Handshake(Some((
|
||||||
server::handshake(io),
|
handshake(io),
|
||||||
self.cfg.clone(),
|
self.cfg.clone(),
|
||||||
self.flow.clone(),
|
self.flow.clone(),
|
||||||
on_connect_data,
|
on_connect_data,
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use time::{Date, OffsetDateTime, PrimitiveDateTime};
|
use time::{Date, OffsetDateTime, PrimitiveDateTime};
|
||||||
|
|
||||||
/// Attempt to parse a `time` string as one of either RFC 1123, RFC 850, or asctime.
|
/// Attempt to parse a `time` string as one of either RFC 1123, RFC 850, or asctime.
|
||||||
pub fn parse_http_date(time: &str) -> Option<PrimitiveDateTime> {
|
pub(crate) fn parse_http_date(time: &str) -> Option<PrimitiveDateTime> {
|
||||||
try_parse_rfc_1123(time)
|
try_parse_rfc_1123(time)
|
||||||
.or_else(|| try_parse_rfc_850(time))
|
.or_else(|| try_parse_rfc_850(time))
|
||||||
.or_else(|| try_parse_asctime(time))
|
.or_else(|| try_parse_asctime(time))
|
||||||
|
|
|
@ -6,7 +6,7 @@ use actix_service::ServiceFactoryExt;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_util::{
|
use futures_util::{
|
||||||
future::{self, ok},
|
future::{self, ok},
|
||||||
StreamExt,
|
StreamExt as _,
|
||||||
};
|
};
|
||||||
|
|
||||||
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
const STR: &str = "Hello World Hello World Hello World Hello World Hello World \
|
||||||
|
|
|
@ -12,8 +12,11 @@ use actix_http::{body, Error, HttpService, Request, Response};
|
||||||
use actix_http_test::test_server;
|
use actix_http_test::test_server;
|
||||||
use actix_service::{fn_service, ServiceFactoryExt};
|
use actix_service::{fn_service, ServiceFactoryExt};
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
use futures_util::future::{err, ok, ready};
|
use futures_core::Stream;
|
||||||
use futures_util::stream::{once, Stream, StreamExt};
|
use futures_util::{
|
||||||
|
future::{err, ok, ready},
|
||||||
|
stream::{once, StreamExt as _},
|
||||||
|
};
|
||||||
use openssl::{
|
use openssl::{
|
||||||
pkey::PKey,
|
pkey::PKey,
|
||||||
ssl::{SslAcceptor, SslMethod},
|
ssl::{SslAcceptor, SslMethod},
|
||||||
|
|
|
@ -10,8 +10,9 @@ use actix_http_test::test_server;
|
||||||
use actix_service::{fn_factory_with_config, fn_service};
|
use actix_service::{fn_factory_with_config, fn_service};
|
||||||
|
|
||||||
use bytes::{Bytes, BytesMut};
|
use bytes::{Bytes, BytesMut};
|
||||||
|
use futures_core::Stream;
|
||||||
use futures_util::future::{self, err, ok};
|
use futures_util::future::{self, err, ok};
|
||||||
use futures_util::stream::{once, Stream, StreamExt};
|
use futures_util::stream::{once, StreamExt as _};
|
||||||
use rustls::{
|
use rustls::{
|
||||||
internal::pemfile::{certs, pkcs8_private_keys},
|
internal::pemfile::{certs, pkcs8_private_keys},
|
||||||
NoClientAuth, ServerConfig as RustlsServerConfig,
|
NoClientAuth, ServerConfig as RustlsServerConfig,
|
||||||
|
|
|
@ -7,7 +7,7 @@ use actix_rt::time::sleep;
|
||||||
use actix_service::fn_service;
|
use actix_service::fn_service;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_util::future::{self, err, ok, ready, FutureExt};
|
use futures_util::future::{self, err, ok, ready, FutureExt};
|
||||||
use futures_util::stream::{once, StreamExt};
|
use futures_util::stream::{once, StreamExt as _};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use actix_http::HttpMessage;
|
use actix_http::HttpMessage;
|
||||||
|
|
|
@ -12,7 +12,7 @@ use actix_utils::dispatcher::Dispatcher;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use futures_util::future;
|
use futures_util::future;
|
||||||
use futures_util::task::{Context, Poll};
|
use futures_util::task::{Context, Poll};
|
||||||
use futures_util::{SinkExt, StreamExt};
|
use futures_util::{SinkExt as _, StreamExt as _};
|
||||||
|
|
||||||
struct WsService<T>(Arc<Mutex<(PhantomData<T>, Cell<bool>)>>);
|
struct WsService<T>(Arc<Mutex<(PhantomData<T>, Cell<bool>)>>);
|
||||||
|
|
||||||
|
|
|
@ -66,12 +66,6 @@ serde_urlencoded = "0.7"
|
||||||
tls-openssl = { version = "0.10.9", package = "openssl", optional = true }
|
tls-openssl = { version = "0.10.9", package = "openssl", optional = true }
|
||||||
tls-rustls = { version = "0.19.0", package = "rustls", optional = true, features = ["dangerous_configuration"] }
|
tls-rustls = { version = "0.19.0", package = "rustls", optional = true, features = ["dangerous_configuration"] }
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies.tls-openssl]
|
|
||||||
version = "0.10.9"
|
|
||||||
package = "openssl"
|
|
||||||
features = ["vendored"]
|
|
||||||
optional = true
|
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
actix-web = { version = "4.0.0-beta.4", features = ["openssl"] }
|
actix-web = { version = "4.0.0-beta.4", features = ["openssl"] }
|
||||||
actix-http = { version = "3.0.0-beta.4", features = ["openssl"] }
|
actix-http = { version = "3.0.0-beta.4", features = ["openssl"] }
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
use std::{
|
use std::{
|
||||||
fmt,
|
|
||||||
future::Future,
|
future::Future,
|
||||||
io, net,
|
net,
|
||||||
pin::Pin,
|
pin::Pin,
|
||||||
task::{Context, Poll},
|
task::{Context, Poll},
|
||||||
};
|
};
|
||||||
|
|
||||||
use actix_codec::{AsyncRead, AsyncWrite, Framed, ReadBuf};
|
use actix_codec::Framed;
|
||||||
use actix_http::{
|
use actix_http::{
|
||||||
body::Body,
|
body::Body,
|
||||||
client::{Connect as ClientConnect, ConnectError, Connection, SendRequestError},
|
client::{
|
||||||
|
Connect as ClientConnect, ConnectError, Connection, ConnectionIo, SendRequestError,
|
||||||
|
},
|
||||||
h1::ClientCodec,
|
h1::ClientCodec,
|
||||||
Payload, RequestHead, RequestHeadType, ResponseHead,
|
Payload, RequestHead, RequestHeadType, ResponseHead,
|
||||||
};
|
};
|
||||||
|
@ -123,7 +124,7 @@ impl<Fut, C, Io> Future for ConnectRequestFuture<Fut, Io>
|
||||||
where
|
where
|
||||||
Fut: Future<Output = Result<C, ConnectError>>,
|
Fut: Future<Output = Result<C, ConnectError>>,
|
||||||
C: Connection<Io = Io>,
|
C: Connection<Io = Io>,
|
||||||
Io: AsyncRead + AsyncWrite + Unpin + 'static,
|
Io: ConnectionIo,
|
||||||
{
|
{
|
||||||
type Output = Result<ConnectResponse, SendRequestError>;
|
type Output = Result<ConnectResponse, SendRequestError>;
|
||||||
|
|
||||||
|
@ -138,14 +139,14 @@ where
|
||||||
let fut = ConnectRequestFuture::Client {
|
let fut = ConnectRequestFuture::Client {
|
||||||
fut: connection.send_request(head, body),
|
fut: connection.send_request(head, body),
|
||||||
};
|
};
|
||||||
self.as_mut().set(fut);
|
self.set(fut);
|
||||||
}
|
}
|
||||||
ConnectRequest::Tunnel(head, ..) => {
|
ConnectRequest::Tunnel(head, ..) => {
|
||||||
// send request
|
// send request
|
||||||
let fut = ConnectRequestFuture::Tunnel {
|
let fut = ConnectRequestFuture::Tunnel {
|
||||||
fut: connection.open_tunnel(RequestHeadType::from(head)),
|
fut: connection.open_tunnel(RequestHeadType::from(head)),
|
||||||
};
|
};
|
||||||
self.as_mut().set(fut);
|
self.set(fut);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.poll(cx)
|
self.poll(cx)
|
||||||
|
@ -158,65 +159,11 @@ where
|
||||||
}
|
}
|
||||||
ConnectRequestProj::Tunnel { fut } => {
|
ConnectRequestProj::Tunnel { fut } => {
|
||||||
let (head, framed) = ready!(fut.as_mut().poll(cx))?;
|
let (head, framed) = ready!(fut.as_mut().poll(cx))?;
|
||||||
let framed = framed.into_map_io(|io| BoxedSocket(Box::new(Socket(io))));
|
let framed = framed.into_map_io(|io| Box::new(io) as _);
|
||||||
Poll::Ready(Ok(ConnectResponse::Tunnel(head, framed)))
|
Poll::Ready(Ok(ConnectResponse::Tunnel(head, framed)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait AsyncSocket {
|
pub type BoxedSocket = Box<dyn ConnectionIo>;
|
||||||
fn as_read(&self) -> &(dyn AsyncRead + Unpin);
|
|
||||||
fn as_read_mut(&mut self) -> &mut (dyn AsyncRead + Unpin);
|
|
||||||
fn as_write(&mut self) -> &mut (dyn AsyncWrite + Unpin);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Socket<T: AsyncRead + AsyncWrite + Unpin>(T);
|
|
||||||
|
|
||||||
impl<T: AsyncRead + AsyncWrite + Unpin> AsyncSocket for Socket<T> {
|
|
||||||
fn as_read(&self) -> &(dyn AsyncRead + Unpin) {
|
|
||||||
&self.0
|
|
||||||
}
|
|
||||||
fn as_read_mut(&mut self) -> &mut (dyn AsyncRead + Unpin) {
|
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
fn as_write(&mut self) -> &mut (dyn AsyncWrite + Unpin) {
|
|
||||||
&mut self.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct BoxedSocket(Box<dyn AsyncSocket>);
|
|
||||||
|
|
||||||
impl fmt::Debug for BoxedSocket {
|
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
|
||||||
write!(f, "BoxedSocket")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsyncRead for BoxedSocket {
|
|
||||||
fn poll_read(
|
|
||||||
self: Pin<&mut Self>,
|
|
||||||
cx: &mut Context<'_>,
|
|
||||||
buf: &mut ReadBuf<'_>,
|
|
||||||
) -> Poll<io::Result<()>> {
|
|
||||||
Pin::new(self.get_mut().0.as_read_mut()).poll_read(cx, buf)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl AsyncWrite for BoxedSocket {
|
|
||||||
fn poll_write(
|
|
||||||
self: Pin<&mut Self>,
|
|
||||||
cx: &mut Context<'_>,
|
|
||||||
buf: &[u8],
|
|
||||||
) -> Poll<io::Result<usize>> {
|
|
||||||
Pin::new(self.get_mut().0.as_write()).poll_write(cx, buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_flush(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
||||||
Pin::new(self.get_mut().0.as_write()).poll_flush(cx)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn poll_shutdown(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<io::Result<()>> {
|
|
||||||
Pin::new(self.get_mut().0.as_write()).poll_shutdown(cx)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ use crate::{dev::Payload, error::PathError, FromRequest, HttpRequest};
|
||||||
/// // extract path info from "/{name}/{count}/index.html" into tuple
|
/// // extract path info from "/{name}/{count}/index.html" into tuple
|
||||||
/// // {name} - deserialize a String
|
/// // {name} - deserialize a String
|
||||||
/// // {count} - deserialize a u32
|
/// // {count} - deserialize a u32
|
||||||
/// #[get("/")]
|
/// #[get("/{name}/{count}/index.html")]
|
||||||
/// async fn index(path: web::Path<(String, u32)>) -> String {
|
/// async fn index(path: web::Path<(String, u32)>) -> String {
|
||||||
/// let (name, count) = path.into_inner();
|
/// let (name, count) = path.into_inner();
|
||||||
/// format!("Welcome {}! {}", name, count)
|
/// format!("Welcome {}! {}", name, count)
|
||||||
|
@ -40,7 +40,7 @@ use crate::{dev::Payload, error::PathError, FromRequest, HttpRequest};
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // extract `Info` from a path using serde
|
/// // extract `Info` from a path using serde
|
||||||
/// #[get("/")]
|
/// #[get("/{name}")]
|
||||||
/// async fn index(info: web::Path<Info>) -> String {
|
/// async fn index(info: web::Path<Info>) -> String {
|
||||||
/// format!("Welcome {}!", info.name)
|
/// format!("Welcome {}!", info.name)
|
||||||
/// }
|
/// }
|
||||||
|
|
Loading…
Reference in New Issue