mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
revert generic service request; add ServerConfig to service factories
This commit is contained in:
parent
e324522389
commit
ca73f178c9
@ -47,6 +47,7 @@ actix-codec = "0.1.1"
|
||||
actix-connector = { git="https://github.com/actix/actix-net.git" }
|
||||
actix-service = { git="https://github.com/actix/actix-net.git" }
|
||||
actix-utils = { git="https://github.com/actix/actix-net.git" }
|
||||
actix-server-config = { git="https://github.com/actix/actix-net.git" }
|
||||
|
||||
base64 = "0.10"
|
||||
backtrace = "0.3"
|
||||
@ -92,6 +93,7 @@ actix-server = { git="https://github.com/actix/actix-net.git", features=["ssl"]
|
||||
#actix-connector = { version = "0.3.0", features=["ssl"] }
|
||||
actix-connector = { git="https://github.com/actix/actix-net.git", features=["ssl"] }
|
||||
actix-http-test = { path="test-server", features=["ssl"] }
|
||||
|
||||
env_logger = "0.6"
|
||||
serde_derive = "1.0"
|
||||
openssl = { version="0.10" }
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::{env, io};
|
||||
|
||||
use actix_http::HttpMessage;
|
||||
use actix_http::{h1, Request, Response};
|
||||
use actix_server::Server;
|
||||
@ -6,9 +8,8 @@ use bytes::Bytes;
|
||||
use futures::Future;
|
||||
use http::header::HeaderValue;
|
||||
use log::info;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
fn main() -> io::Result<()> {
|
||||
env::set_var("RUST_LOG", "echo=info");
|
||||
env_logger::init();
|
||||
|
||||
@ -27,7 +28,6 @@ fn main() {
|
||||
})
|
||||
})
|
||||
.map(|_| ())
|
||||
})
|
||||
.unwrap()
|
||||
.run();
|
||||
})?
|
||||
.run()
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::{env, io};
|
||||
|
||||
use actix_http::http::HeaderValue;
|
||||
use actix_http::HttpMessage;
|
||||
use actix_http::{h1, Error, Request, Response};
|
||||
@ -6,7 +8,6 @@ use actix_service::NewService;
|
||||
use bytes::Bytes;
|
||||
use futures::Future;
|
||||
use log::info;
|
||||
use std::env;
|
||||
|
||||
fn handle_request(mut req: Request) -> impl Future<Item = Response, Error = Error> {
|
||||
req.body().limit(512).from_err().and_then(|bytes: Bytes| {
|
||||
@ -17,7 +18,7 @@ fn handle_request(mut req: Request) -> impl Future<Item = Response, Error = Erro
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
fn main() -> io::Result<()> {
|
||||
env::set_var("RUST_LOG", "echo=info");
|
||||
env_logger::init();
|
||||
|
||||
@ -29,7 +30,6 @@ fn main() {
|
||||
.server_hostname("localhost")
|
||||
.finish(|_req: Request| handle_request(_req))
|
||||
.map(|_| ())
|
||||
})
|
||||
.unwrap()
|
||||
.run();
|
||||
})?
|
||||
.run()
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
use std::{env, io};
|
||||
|
||||
use actix_codec::Framed;
|
||||
use actix_http::{h1, Response, SendResponse, ServiceConfig};
|
||||
use actix_server::Server;
|
||||
@ -5,9 +7,8 @@ use actix_service::NewService;
|
||||
use actix_utils::framed::IntoFramed;
|
||||
use actix_utils::stream::TakeItem;
|
||||
use futures::Future;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
fn main() -> io::Result<()> {
|
||||
env::set_var("RUST_LOG", "framed_hello=info");
|
||||
env_logger::init();
|
||||
|
||||
@ -20,7 +21,6 @@ fn main() {
|
||||
.map_err(|_| ())
|
||||
.map(|_| ())
|
||||
})
|
||||
})
|
||||
.unwrap()
|
||||
.run();
|
||||
})?
|
||||
.run()
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
use std::{env, io};
|
||||
|
||||
use actix_http::{h1, Response};
|
||||
use actix_server::Server;
|
||||
use actix_service::NewService;
|
||||
use futures::future;
|
||||
use http::header::HeaderValue;
|
||||
use log::info;
|
||||
use std::env;
|
||||
|
||||
fn main() {
|
||||
fn main() -> io::Result<()> {
|
||||
env::set_var("RUST_LOG", "hello_world=info");
|
||||
env_logger::init();
|
||||
|
||||
@ -23,7 +24,6 @@ fn main() {
|
||||
future::ok::<_, ()>(res.body("Hello world!"))
|
||||
})
|
||||
.map(|_| ())
|
||||
})
|
||||
.unwrap()
|
||||
.run();
|
||||
})?
|
||||
.run()
|
||||
}
|
||||
|
@ -133,8 +133,11 @@ impl Connector {
|
||||
/// Finish configuration process and create connector service.
|
||||
pub fn service(
|
||||
self,
|
||||
) -> impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone
|
||||
{
|
||||
) -> impl Service<
|
||||
Request = Connect,
|
||||
Response = impl Connection,
|
||||
Error = ConnectorError,
|
||||
> + Clone {
|
||||
#[cfg(not(feature = "ssl"))]
|
||||
{
|
||||
let connector = TimeoutService::new(
|
||||
@ -238,7 +241,11 @@ mod connect_impl {
|
||||
pub(crate) struct InnerConnector<T, Io>
|
||||
where
|
||||
Io: AsyncRead + AsyncWrite + 'static,
|
||||
T: Service<Connect, Response = (Connect, Io, Protocol), Error = ConnectorError>,
|
||||
T: Service<
|
||||
Request = Connect,
|
||||
Response = (Connect, Io, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
{
|
||||
pub(crate) tcp_pool: ConnectionPool<T, Io>,
|
||||
}
|
||||
@ -246,8 +253,11 @@ mod connect_impl {
|
||||
impl<T, Io> Clone for InnerConnector<T, Io>
|
||||
where
|
||||
Io: AsyncRead + AsyncWrite + 'static,
|
||||
T: Service<Connect, Response = (Connect, Io, Protocol), Error = ConnectorError>
|
||||
+ Clone,
|
||||
T: Service<
|
||||
Request = Connect,
|
||||
Response = (Connect, Io, Protocol),
|
||||
Error = ConnectorError,
|
||||
> + Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
InnerConnector {
|
||||
@ -256,15 +266,16 @@ mod connect_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, Io> Service<Connect> for InnerConnector<T, Io>
|
||||
impl<T, Io> Service for InnerConnector<T, Io>
|
||||
where
|
||||
Io: AsyncRead + AsyncWrite + 'static,
|
||||
T: Service<Connect, Response = (Connect, Io, Protocol), Error = ConnectorError>,
|
||||
{
|
||||
type Request = Connect;
|
||||
type Response = IoConnection<Io>;
|
||||
type Error = ConnectorError;
|
||||
type Future = Either<
|
||||
<ConnectionPool<T, Io> as Service<Connect>>::Future,
|
||||
<ConnectionPool<T, Io> as Service>::Future,
|
||||
FutureResult<IoConnection<Io>, ConnectorError>,
|
||||
>;
|
||||
|
||||
@ -299,12 +310,12 @@ mod connect_impl {
|
||||
Io1: AsyncRead + AsyncWrite + 'static,
|
||||
Io2: AsyncRead + AsyncWrite + 'static,
|
||||
T1: Service<
|
||||
Connect,
|
||||
Request = Connect,
|
||||
Response = (Connect, Io1, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
T2: Service<
|
||||
Connect,
|
||||
Request = Connect,
|
||||
Response = (Connect, Io2, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
@ -318,12 +329,12 @@ mod connect_impl {
|
||||
Io1: AsyncRead + AsyncWrite + 'static,
|
||||
Io2: AsyncRead + AsyncWrite + 'static,
|
||||
T1: Service<
|
||||
Connect,
|
||||
Request = Connect,
|
||||
Response = (Connect, Io1, Protocol),
|
||||
Error = ConnectorError,
|
||||
> + Clone,
|
||||
T2: Service<
|
||||
Connect,
|
||||
Request = Connect,
|
||||
Response = (Connect, Io2, Protocol),
|
||||
Error = ConnectorError,
|
||||
> + Clone,
|
||||
@ -336,21 +347,22 @@ mod connect_impl {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T1, T2, Io1, Io2> Service<Connect> for InnerConnector<T1, T2, Io1, Io2>
|
||||
impl<T1, T2, Io1, Io2> Service for InnerConnector<T1, T2, Io1, Io2>
|
||||
where
|
||||
Io1: AsyncRead + AsyncWrite + 'static,
|
||||
Io2: AsyncRead + AsyncWrite + 'static,
|
||||
T1: Service<
|
||||
Connect,
|
||||
Request = Connect,
|
||||
Response = (Connect, Io1, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
T2: Service<
|
||||
Connect,
|
||||
Request = Connect,
|
||||
Response = (Connect, Io2, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
{
|
||||
type Request = Connect;
|
||||
type Response = EitherConnection<Io1, Io2>;
|
||||
type Error = ConnectorError;
|
||||
type Future = Either<
|
||||
@ -385,15 +397,23 @@ mod connect_impl {
|
||||
pub(crate) struct InnerConnectorResponseA<T, Io1, Io2>
|
||||
where
|
||||
Io1: AsyncRead + AsyncWrite + 'static,
|
||||
T: Service<Connect, Response = (Connect, Io1, Protocol), Error = ConnectorError>,
|
||||
T: Service<
|
||||
Request = Connect,
|
||||
Response = (Connect, Io1, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
{
|
||||
fut: <ConnectionPool<T, Io1> as Service<Connect>>::Future,
|
||||
fut: <ConnectionPool<T, Io1> as Service>::Future,
|
||||
_t: PhantomData<Io2>,
|
||||
}
|
||||
|
||||
impl<T, Io1, Io2> Future for InnerConnectorResponseA<T, Io1, Io2>
|
||||
where
|
||||
T: Service<Connect, Response = (Connect, Io1, Protocol), Error = ConnectorError>,
|
||||
T: Service<
|
||||
Request = Connect,
|
||||
Response = (Connect, Io1, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
Io1: AsyncRead + AsyncWrite + 'static,
|
||||
Io2: AsyncRead + AsyncWrite + 'static,
|
||||
{
|
||||
@ -411,15 +431,23 @@ mod connect_impl {
|
||||
pub(crate) struct InnerConnectorResponseB<T, Io1, Io2>
|
||||
where
|
||||
Io2: AsyncRead + AsyncWrite + 'static,
|
||||
T: Service<Connect, Response = (Connect, Io2, Protocol), Error = ConnectorError>,
|
||||
T: Service<
|
||||
Request = Connect,
|
||||
Response = (Connect, Io2, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
{
|
||||
fut: <ConnectionPool<T, Io2> as Service<Connect>>::Future,
|
||||
fut: <ConnectionPool<T, Io2> as Service>::Future,
|
||||
_t: PhantomData<Io1>,
|
||||
}
|
||||
|
||||
impl<T, Io1, Io2> Future for InnerConnectorResponseB<T, Io1, Io2>
|
||||
where
|
||||
T: Service<Connect, Response = (Connect, Io2, Protocol), Error = ConnectorError>,
|
||||
T: Service<
|
||||
Request = Connect,
|
||||
Response = (Connect, Io2, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
Io1: AsyncRead + AsyncWrite + 'static,
|
||||
Io2: AsyncRead + AsyncWrite + 'static,
|
||||
{
|
||||
|
@ -48,7 +48,11 @@ pub(crate) struct ConnectionPool<T, Io: AsyncRead + AsyncWrite + 'static>(
|
||||
impl<T, Io> ConnectionPool<T, Io>
|
||||
where
|
||||
Io: AsyncRead + AsyncWrite + 'static,
|
||||
T: Service<Connect, Response = (Connect, Io, Protocol), Error = ConnectorError>,
|
||||
T: Service<
|
||||
Request = Connect,
|
||||
Response = (Connect, Io, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
{
|
||||
pub(crate) fn new(
|
||||
connector: T,
|
||||
@ -84,11 +88,16 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, Io> Service<Connect> for ConnectionPool<T, Io>
|
||||
impl<T, Io> Service for ConnectionPool<T, Io>
|
||||
where
|
||||
Io: AsyncRead + AsyncWrite + 'static,
|
||||
T: Service<Connect, Response = (Connect, Io, Protocol), Error = ConnectorError>,
|
||||
T: Service<
|
||||
Request = Connect,
|
||||
Response = (Connect, Io, Protocol),
|
||||
Error = ConnectorError,
|
||||
>,
|
||||
{
|
||||
type Request = Connect;
|
||||
type Response = IoConnection<Io>;
|
||||
type Error = ConnectorError;
|
||||
type Future = Either<
|
||||
|
@ -176,7 +176,7 @@ where
|
||||
) -> impl Future<Item = ClientResponse, Error = SendRequestError>
|
||||
where
|
||||
B: 'static,
|
||||
T: Service<Connect, Response = I, Error = ConnectorError>,
|
||||
T: Service<Request = Connect, Response = I, Error = ConnectorError>,
|
||||
I: Connection,
|
||||
{
|
||||
let Self { head, body } = self;
|
||||
|
@ -36,14 +36,14 @@ bitflags! {
|
||||
}
|
||||
|
||||
/// Dispatcher for HTTP/1.1 protocol
|
||||
pub struct Dispatcher<T, S: Service<Request> + 'static, B: MessageBody>
|
||||
pub struct Dispatcher<T, S: Service<Request = Request> + 'static, B: MessageBody>
|
||||
where
|
||||
S::Error: Debug,
|
||||
{
|
||||
inner: Option<InnerDispatcher<T, S, B>>,
|
||||
}
|
||||
|
||||
struct InnerDispatcher<T, S: Service<Request> + 'static, B: MessageBody>
|
||||
struct InnerDispatcher<T, S: Service<Request = Request> + 'static, B: MessageBody>
|
||||
where
|
||||
S::Error: Debug,
|
||||
{
|
||||
@ -67,13 +67,13 @@ enum DispatcherMessage {
|
||||
Error(Response<()>),
|
||||
}
|
||||
|
||||
enum State<S: Service<Request>, B: MessageBody> {
|
||||
enum State<S: Service<Request = Request>, B: MessageBody> {
|
||||
None,
|
||||
ServiceCall(S::Future),
|
||||
SendPayload(ResponseBody<B>),
|
||||
}
|
||||
|
||||
impl<S: Service<Request>, B: MessageBody> State<S, B> {
|
||||
impl<S: Service<Request = Request>, B: MessageBody> State<S, B> {
|
||||
fn is_empty(&self) -> bool {
|
||||
if let State::None = self {
|
||||
true
|
||||
@ -86,7 +86,7 @@ impl<S: Service<Request>, B: MessageBody> State<S, B> {
|
||||
impl<T, S, B> Dispatcher<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody,
|
||||
@ -145,7 +145,7 @@ where
|
||||
impl<T, S, B> InnerDispatcher<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody,
|
||||
@ -465,7 +465,7 @@ where
|
||||
impl<T, S, B> Future for Dispatcher<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request>,
|
||||
S: Service<Request = Request>,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody,
|
||||
|
@ -3,6 +3,7 @@ use std::marker::PhantomData;
|
||||
use std::net;
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_server_config::ServerConfig as SrvConfig;
|
||||
use actix_service::{IntoNewService, NewService, Service};
|
||||
use actix_utils::cloneable::CloneableService;
|
||||
use futures::future::{ok, FutureResult};
|
||||
@ -28,14 +29,14 @@ pub struct H1Service<T, S, B> {
|
||||
|
||||
impl<T, S, B> H1Service<T, S, B>
|
||||
where
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
S::Service: 'static,
|
||||
B: MessageBody,
|
||||
{
|
||||
/// Create new `HttpService` instance with default config.
|
||||
pub fn new<F: IntoNewService<S, Request>>(service: F) -> Self {
|
||||
pub fn new<F: IntoNewService<S, SrvConfig>>(service: F) -> Self {
|
||||
let cfg = ServiceConfig::new(KeepAlive::Timeout(5), 5000, 0);
|
||||
|
||||
H1Service {
|
||||
@ -46,7 +47,7 @@ where
|
||||
}
|
||||
|
||||
/// Create new `HttpService` instance with config.
|
||||
pub fn with_config<F: IntoNewService<S, Request>>(
|
||||
pub fn with_config<F: IntoNewService<S, SrvConfig>>(
|
||||
cfg: ServiceConfig,
|
||||
service: F,
|
||||
) -> Self {
|
||||
@ -63,24 +64,25 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> NewService<T> for H1Service<T, S, B>
|
||||
impl<T, S, B> NewService<SrvConfig> for H1Service<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
S::Service: 'static,
|
||||
B: MessageBody,
|
||||
{
|
||||
type Request = T;
|
||||
type Response = ();
|
||||
type Error = DispatchError;
|
||||
type InitError = S::InitError;
|
||||
type Service = H1ServiceHandler<T, S::Service, B>;
|
||||
type Future = H1ServiceResponse<T, S, B>;
|
||||
|
||||
fn new_service(&self, _: &()) -> Self::Future {
|
||||
fn new_service(&self, cfg: &SrvConfig) -> Self::Future {
|
||||
H1ServiceResponse {
|
||||
fut: self.srv.new_service(&()).into_future(),
|
||||
fut: self.srv.new_service(cfg).into_future(),
|
||||
cfg: Some(self.cfg.clone()),
|
||||
_t: PhantomData,
|
||||
}
|
||||
@ -103,7 +105,7 @@ pub struct H1ServiceBuilder<T, S> {
|
||||
|
||||
impl<T, S> H1ServiceBuilder<T, S>
|
||||
where
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Error: Debug,
|
||||
{
|
||||
/// Create instance of `ServiceConfigBuilder`
|
||||
@ -201,7 +203,7 @@ where
|
||||
pub fn finish<F, B>(self, service: F) -> H1Service<T, S, B>
|
||||
where
|
||||
B: MessageBody,
|
||||
F: IntoNewService<S, Request>,
|
||||
F: IntoNewService<S, SrvConfig>,
|
||||
{
|
||||
let cfg = ServiceConfig::new(
|
||||
self.keep_alive,
|
||||
@ -217,7 +219,7 @@ where
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub struct H1ServiceResponse<T, S: NewService<Request>, B> {
|
||||
pub struct H1ServiceResponse<T, S: NewService<SrvConfig, Request = Request>, B> {
|
||||
fut: <S::Future as IntoFuture>::Future,
|
||||
cfg: Option<ServiceConfig>,
|
||||
_t: PhantomData<(T, B)>,
|
||||
@ -226,7 +228,7 @@ pub struct H1ServiceResponse<T, S: NewService<Request>, B> {
|
||||
impl<T, S, B> Future for H1ServiceResponse<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
@ -253,7 +255,7 @@ pub struct H1ServiceHandler<T, S: 'static, B> {
|
||||
|
||||
impl<T, S, B> H1ServiceHandler<T, S, B>
|
||||
where
|
||||
S: Service<Request>,
|
||||
S: Service<Request = Request>,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody,
|
||||
@ -267,14 +269,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> Service<T> for H1ServiceHandler<T, S, B>
|
||||
impl<T, S, B> Service for H1ServiceHandler<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request>,
|
||||
S: Service<Request = Request>,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody,
|
||||
{
|
||||
type Request = T;
|
||||
type Response = ();
|
||||
type Error = DispatchError;
|
||||
type Future = Dispatcher<T, S, B>;
|
||||
@ -311,17 +314,18 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> NewService<T> for OneRequest<T>
|
||||
impl<T> NewService<SrvConfig> for OneRequest<T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
{
|
||||
type Request = T;
|
||||
type Response = (Request, Framed<T, Codec>);
|
||||
type Error = ParseError;
|
||||
type InitError = ();
|
||||
type Service = OneRequestService<T>;
|
||||
type Future = FutureResult<Self::Service, Self::InitError>;
|
||||
|
||||
fn new_service(&self, _: &()) -> Self::Future {
|
||||
fn new_service(&self, _: &SrvConfig) -> Self::Future {
|
||||
ok(OneRequestService {
|
||||
config: self.config.clone(),
|
||||
_t: PhantomData,
|
||||
@ -336,10 +340,11 @@ pub struct OneRequestService<T> {
|
||||
_t: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> Service<T> for OneRequestService<T>
|
||||
impl<T> Service for OneRequestService<T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
{
|
||||
type Request = T;
|
||||
type Response = (Request, Framed<T, Codec>);
|
||||
type Error = ParseError;
|
||||
type Future = OneRequestServiceResponse<T>;
|
||||
|
@ -38,7 +38,7 @@ bitflags! {
|
||||
/// Dispatcher for HTTP/2 protocol
|
||||
pub struct Dispatcher<
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
B: MessageBody,
|
||||
> {
|
||||
flags: Flags,
|
||||
@ -53,7 +53,7 @@ pub struct Dispatcher<
|
||||
impl<T, S, B> Dispatcher<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: fmt::Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
@ -95,7 +95,7 @@ where
|
||||
impl<T, S, B> Future for Dispatcher<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: fmt::Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
@ -141,20 +141,20 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
struct ServiceResponse<S: Service<Request>, B> {
|
||||
struct ServiceResponse<S: Service, B> {
|
||||
state: ServiceResponseState<S, B>,
|
||||
config: ServiceConfig,
|
||||
buffer: Option<Bytes>,
|
||||
}
|
||||
|
||||
enum ServiceResponseState<S: Service<Request>, B> {
|
||||
enum ServiceResponseState<S: Service, B> {
|
||||
ServiceCall(S::Future, Option<SendResponse<Bytes>>),
|
||||
SendPayload(SendStream<Bytes>, ResponseBody<B>),
|
||||
}
|
||||
|
||||
impl<S, B> ServiceResponse<S, B>
|
||||
where
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: fmt::Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
@ -222,7 +222,7 @@ where
|
||||
|
||||
impl<S, B> Future for ServiceResponse<S, B>
|
||||
where
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: fmt::Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
|
@ -3,6 +3,7 @@ use std::marker::PhantomData;
|
||||
use std::{io, net};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed};
|
||||
use actix_server_config::ServerConfig as SrvConfig;
|
||||
use actix_service::{IntoNewService, NewService, Service};
|
||||
use actix_utils::cloneable::CloneableService;
|
||||
use bytes::Bytes;
|
||||
@ -30,14 +31,14 @@ pub struct H2Service<T, S, B> {
|
||||
|
||||
impl<T, S, B> H2Service<T, S, B>
|
||||
where
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Error: Debug + 'static,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
/// Create new `HttpService` instance.
|
||||
pub fn new<F: IntoNewService<S, Request>>(service: F) -> Self {
|
||||
pub fn new<F: IntoNewService<S, SrvConfig>>(service: F) -> Self {
|
||||
let cfg = ServiceConfig::new(KeepAlive::Timeout(5), 5000, 0);
|
||||
|
||||
H2Service {
|
||||
@ -48,7 +49,7 @@ where
|
||||
}
|
||||
|
||||
/// Create new `HttpService` instance with config.
|
||||
pub fn with_config<F: IntoNewService<S, Request>>(
|
||||
pub fn with_config<F: IntoNewService<S, SrvConfig>>(
|
||||
cfg: ServiceConfig,
|
||||
service: F,
|
||||
) -> Self {
|
||||
@ -65,24 +66,25 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> NewService<T> for H2Service<T, S, B>
|
||||
impl<T, S, B> NewService<SrvConfig> for H2Service<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
type Request = T;
|
||||
type Response = ();
|
||||
type Error = DispatchError;
|
||||
type InitError = S::InitError;
|
||||
type Service = H2ServiceHandler<T, S::Service, B>;
|
||||
type Future = H2ServiceResponse<T, S, B>;
|
||||
|
||||
fn new_service(&self, _: &()) -> Self::Future {
|
||||
fn new_service(&self, cfg: &SrvConfig) -> Self::Future {
|
||||
H2ServiceResponse {
|
||||
fut: self.srv.new_service(&()).into_future(),
|
||||
fut: self.srv.new_service(cfg).into_future(),
|
||||
cfg: Some(self.cfg.clone()),
|
||||
_t: PhantomData,
|
||||
}
|
||||
@ -105,7 +107,7 @@ pub struct H2ServiceBuilder<T, S> {
|
||||
|
||||
impl<T, S> H2ServiceBuilder<T, S>
|
||||
where
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Error: Debug + 'static,
|
||||
{
|
||||
@ -204,7 +206,7 @@ where
|
||||
pub fn finish<F, B>(self, service: F) -> H2Service<T, S, B>
|
||||
where
|
||||
B: MessageBody,
|
||||
F: IntoNewService<S, Request>,
|
||||
F: IntoNewService<S, SrvConfig>,
|
||||
{
|
||||
let cfg = ServiceConfig::new(
|
||||
self.keep_alive,
|
||||
@ -220,7 +222,7 @@ where
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub struct H2ServiceResponse<T, S: NewService<Request>, B> {
|
||||
pub struct H2ServiceResponse<T, S: NewService<SrvConfig, Request = Request>, B> {
|
||||
fut: <S::Future as IntoFuture>::Future,
|
||||
cfg: Option<ServiceConfig>,
|
||||
_t: PhantomData<(T, B)>,
|
||||
@ -229,7 +231,7 @@ pub struct H2ServiceResponse<T, S: NewService<Request>, B> {
|
||||
impl<T, S, B> Future for H2ServiceResponse<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Response: Into<Response<B>>,
|
||||
S::Error: Debug,
|
||||
@ -256,7 +258,7 @@ pub struct H2ServiceHandler<T, S: 'static, B> {
|
||||
|
||||
impl<T, S, B> H2ServiceHandler<T, S, B>
|
||||
where
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
@ -270,14 +272,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> Service<T> for H2ServiceHandler<T, S, B>
|
||||
impl<T, S, B> Service for H2ServiceHandler<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
type Request = T;
|
||||
type Response = ();
|
||||
type Error = DispatchError;
|
||||
type Future = H2ServiceHandlerResponse<T, S, B>;
|
||||
@ -300,7 +303,11 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
enum State<T: AsyncRead + AsyncWrite, S: Service<Request> + 'static, B: MessageBody> {
|
||||
enum State<
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request = Request> + 'static,
|
||||
B: MessageBody,
|
||||
> {
|
||||
Incoming(Dispatcher<T, S, B>),
|
||||
Handshake(
|
||||
Option<CloneableService<S>>,
|
||||
@ -312,7 +319,7 @@ enum State<T: AsyncRead + AsyncWrite, S: Service<Request> + 'static, B: MessageB
|
||||
pub struct H2ServiceHandlerResponse<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
@ -323,7 +330,7 @@ where
|
||||
impl<T, S, B> Future for H2ServiceHandlerResponse<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody,
|
||||
|
@ -97,8 +97,7 @@ pub use self::message::{Head, Message, RequestHead, ResponseHead};
|
||||
pub use self::payload::{Payload, PayloadStream};
|
||||
pub use self::request::Request;
|
||||
pub use self::response::Response;
|
||||
pub use self::service::HttpService;
|
||||
pub use self::service::{SendError, SendResponse};
|
||||
pub use self::service::{HttpService, SendError, SendResponse};
|
||||
|
||||
pub mod dev {
|
||||
//! The `actix-web` prelude for library developers
|
||||
|
@ -22,11 +22,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, R, E> NewService<Result<R, (E, Framed<T, Codec>)>> for SendError<T, R, E>
|
||||
impl<T, R, E> NewService for SendError<T, R, E>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
E: ResponseError,
|
||||
{
|
||||
type Request = Result<R, (E, Framed<T, Codec>)>;
|
||||
type Response = R;
|
||||
type Error = (E, Framed<T, Codec>);
|
||||
type InitError = ();
|
||||
@ -38,11 +39,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, R, E> Service<Result<R, (E, Framed<T, Codec>)>> for SendError<T, R, E>
|
||||
impl<T, R, E> Service for SendError<T, R, E>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
E: ResponseError,
|
||||
{
|
||||
type Request = Result<R, (E, Framed<T, Codec>)>;
|
||||
type Response = R;
|
||||
type Error = (E, Framed<T, Codec>);
|
||||
type Future = Either<FutureResult<R, (E, Framed<T, Codec>)>, SendErrorFut<T, R, E>>;
|
||||
@ -128,11 +130,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> NewService<(Response<B>, Framed<T, Codec>)> for SendResponse<T, B>
|
||||
impl<T, B> NewService for SendResponse<T, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
B: MessageBody,
|
||||
{
|
||||
type Request = (Response<B>, Framed<T, Codec>);
|
||||
type Response = Framed<T, Codec>;
|
||||
type Error = Error;
|
||||
type InitError = ();
|
||||
@ -144,11 +147,12 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, B> Service<(Response<B>, Framed<T, Codec>)> for SendResponse<T, B>
|
||||
impl<T, B> Service for SendResponse<T, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
B: MessageBody,
|
||||
{
|
||||
type Request = (Response<B>, Framed<T, Codec>);
|
||||
type Response = Framed<T, Codec>;
|
||||
type Error = Error;
|
||||
type Future = SendResponseFut<T, B>;
|
||||
|
@ -3,6 +3,7 @@ use std::marker::PhantomData;
|
||||
use std::{fmt, io, net};
|
||||
|
||||
use actix_codec::{AsyncRead, AsyncWrite, Framed, FramedParts};
|
||||
use actix_server_config::ServerConfig as SrvConfig;
|
||||
use actix_service::{IntoNewService, NewService, Service};
|
||||
use actix_utils::cloneable::CloneableService;
|
||||
use bytes::{Buf, BufMut, Bytes, BytesMut};
|
||||
@ -27,14 +28,14 @@ pub struct HttpService<T, S, B> {
|
||||
|
||||
impl<T, S, B> HttpService<T, S, B>
|
||||
where
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Error: Debug + 'static,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
/// Create new `HttpService` instance.
|
||||
pub fn new<F: IntoNewService<S, Request>>(service: F) -> Self {
|
||||
pub fn new<F: IntoNewService<S, SrvConfig>>(service: F) -> Self {
|
||||
let cfg = ServiceConfig::new(KeepAlive::Timeout(5), 5000, 0);
|
||||
|
||||
HttpService {
|
||||
@ -45,7 +46,7 @@ where
|
||||
}
|
||||
|
||||
/// Create new `HttpService` instance with config.
|
||||
pub fn with_config<F: IntoNewService<S, Request>>(
|
||||
pub fn with_config<F: IntoNewService<S, SrvConfig>>(
|
||||
cfg: ServiceConfig,
|
||||
service: F,
|
||||
) -> Self {
|
||||
@ -62,24 +63,25 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> NewService<T> for HttpService<T, S, B>
|
||||
impl<T, S, B> NewService<SrvConfig> for HttpService<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + 'static,
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
type Request = T;
|
||||
type Response = ();
|
||||
type Error = DispatchError;
|
||||
type InitError = S::InitError;
|
||||
type Service = HttpServiceHandler<T, S::Service, B>;
|
||||
type Future = HttpServiceResponse<T, S, B>;
|
||||
|
||||
fn new_service(&self, _: &()) -> Self::Future {
|
||||
fn new_service(&self, cfg: &SrvConfig) -> Self::Future {
|
||||
HttpServiceResponse {
|
||||
fut: self.srv.new_service(&()).into_future(),
|
||||
fut: self.srv.new_service(cfg).into_future(),
|
||||
cfg: Some(self.cfg.clone()),
|
||||
_t: PhantomData,
|
||||
}
|
||||
@ -102,7 +104,7 @@ pub struct HttpServiceBuilder<T, S> {
|
||||
|
||||
impl<T, S> HttpServiceBuilder<T, S>
|
||||
where
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Error: Debug + 'static,
|
||||
{
|
||||
@ -220,7 +222,7 @@ where
|
||||
pub fn finish<F, B>(self, service: F) -> HttpService<T, S, B>
|
||||
where
|
||||
B: MessageBody,
|
||||
F: IntoNewService<S, Request>,
|
||||
F: IntoNewService<S, SrvConfig>,
|
||||
{
|
||||
let cfg = ServiceConfig::new(
|
||||
self.keep_alive,
|
||||
@ -236,7 +238,7 @@ where
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
pub struct HttpServiceResponse<T, S: NewService<Request>, B> {
|
||||
pub struct HttpServiceResponse<T, S: NewService<SrvConfig>, B> {
|
||||
fut: <S::Future as IntoFuture>::Future,
|
||||
cfg: Option<ServiceConfig>,
|
||||
_t: PhantomData<(T, B)>,
|
||||
@ -245,7 +247,7 @@ pub struct HttpServiceResponse<T, S: NewService<Request>, B> {
|
||||
impl<T, S, B> Future for HttpServiceResponse<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: NewService<Request>,
|
||||
S: NewService<SrvConfig, Request = Request>,
|
||||
S::Service: 'static,
|
||||
S::Response: Into<Response<B>>,
|
||||
S::Error: Debug,
|
||||
@ -272,7 +274,7 @@ pub struct HttpServiceHandler<T, S: 'static, B> {
|
||||
|
||||
impl<T, S, B> HttpServiceHandler<T, S, B>
|
||||
where
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
@ -286,14 +288,15 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, S, B> Service<T> for HttpServiceHandler<T, S, B>
|
||||
impl<T, S, B> Service for HttpServiceHandler<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + 'static,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
{
|
||||
type Request = T;
|
||||
type Response = ();
|
||||
type Error = DispatchError;
|
||||
type Future = HttpServiceHandlerResponse<T, S, B>;
|
||||
@ -317,7 +320,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
enum State<T, S: Service<Request> + 'static, B: MessageBody>
|
||||
enum State<T, S: Service<Request = Request> + 'static, B: MessageBody>
|
||||
where
|
||||
S::Error: fmt::Debug,
|
||||
T: AsyncRead + AsyncWrite + 'static,
|
||||
@ -331,7 +334,7 @@ where
|
||||
pub struct HttpServiceHandlerResponse<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite + 'static,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody + 'static,
|
||||
@ -344,7 +347,7 @@ const HTTP2_PREFACE: [u8; 14] = *b"PRI * HTTP/2.0";
|
||||
impl<T, S, B> Future for HttpServiceHandlerResponse<T, S, B>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Request> + 'static,
|
||||
S: Service<Request = Request> + 'static,
|
||||
S::Error: Debug,
|
||||
S::Response: Into<Response<B>>,
|
||||
B: MessageBody,
|
||||
|
@ -25,6 +25,20 @@ impl Protocol {
|
||||
}
|
||||
}
|
||||
|
||||
fn is_http(self) -> bool {
|
||||
match self {
|
||||
Protocol::Https | Protocol::Http => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn is_secure(self) -> bool {
|
||||
match self {
|
||||
Protocol::Https | Protocol::Wss => true,
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn port(self) -> u16 {
|
||||
match self {
|
||||
Protocol::Http | Protocol::Ws => 80,
|
||||
|
@ -26,7 +26,7 @@ pub type DefaultClient = Client<DefaultConnector>;
|
||||
/// WebSocket's client
|
||||
pub struct Client<T>
|
||||
where
|
||||
T: Service<TcpConnect, Error = ConnectorError>,
|
||||
T: Service<Request = TcpConnect, Error = ConnectorError>,
|
||||
T::Response: AsyncRead + AsyncWrite,
|
||||
{
|
||||
connector: T,
|
||||
@ -34,7 +34,7 @@ where
|
||||
|
||||
impl<T> Client<T>
|
||||
where
|
||||
T: Service<TcpConnect, Error = ConnectorError>,
|
||||
T: Service<Request = TcpConnect, Error = ConnectorError>,
|
||||
T::Response: AsyncRead + AsyncWrite,
|
||||
{
|
||||
/// Create new websocket's client factory
|
||||
@ -51,7 +51,7 @@ impl Default for Client<DefaultConnector> {
|
||||
|
||||
impl<T> Clone for Client<T>
|
||||
where
|
||||
T: Service<TcpConnect, Error = ConnectorError> + Clone,
|
||||
T: Service<Request = TcpConnect, Error = ConnectorError> + Clone,
|
||||
T::Response: AsyncRead + AsyncWrite,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
@ -61,12 +61,13 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Service<Connect> for Client<T>
|
||||
impl<T> Service for Client<T>
|
||||
where
|
||||
T: Service<TcpConnect, Error = ConnectorError>,
|
||||
T: Service<Request = TcpConnect, Error = ConnectorError>,
|
||||
T::Response: AsyncRead + AsyncWrite + 'static,
|
||||
T::Future: 'static,
|
||||
{
|
||||
type Request = Connect;
|
||||
type Response = Framed<T::Response, Codec>;
|
||||
type Error = ClientError;
|
||||
type Future = Either<
|
||||
|
@ -20,7 +20,8 @@ impl<T> Default for VerifyWebSockets<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> NewService<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
|
||||
impl<T> NewService for VerifyWebSockets<T> {
|
||||
type Request = (Request, Framed<T, Codec>);
|
||||
type Response = (Request, Framed<T, Codec>);
|
||||
type Error = (HandshakeError, Framed<T, Codec>);
|
||||
type InitError = ();
|
||||
@ -32,7 +33,8 @@ impl<T> NewService<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> Service<(Request, Framed<T, Codec>)> for VerifyWebSockets<T> {
|
||||
impl<T> Service for VerifyWebSockets<T> {
|
||||
type Request = (Request, Framed<T, Codec>);
|
||||
type Response = (Request, Framed<T, Codec>);
|
||||
type Error = (HandshakeError, Framed<T, Codec>);
|
||||
type Future = FutureResult<Self::Response, Self::Error>;
|
||||
|
@ -7,7 +7,7 @@ use super::{Codec, Frame, Message};
|
||||
|
||||
pub struct Transport<S, T>
|
||||
where
|
||||
S: Service<Frame, Response = Message> + 'static,
|
||||
S: Service<Request = Frame, Response = Message> + 'static,
|
||||
T: AsyncRead + AsyncWrite,
|
||||
{
|
||||
inner: FramedTransport<S, T, Codec>,
|
||||
@ -16,17 +16,17 @@ where
|
||||
impl<S, T> Transport<S, T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Frame, Response = Message>,
|
||||
S: Service<Request = Frame, Response = Message>,
|
||||
S::Future: 'static,
|
||||
S::Error: 'static,
|
||||
{
|
||||
pub fn new<F: IntoService<S, Frame>>(io: T, service: F) -> Self {
|
||||
pub fn new<F: IntoService<S>>(io: T, service: F) -> Self {
|
||||
Transport {
|
||||
inner: FramedTransport::new(Framed::new(io, Codec::new()), service),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with<F: IntoService<S, Frame>>(framed: Framed<T, Codec>, service: F) -> Self {
|
||||
pub fn with<F: IntoService<S>>(framed: Framed<T, Codec>, service: F) -> Self {
|
||||
Transport {
|
||||
inner: FramedTransport::new(framed, service),
|
||||
}
|
||||
@ -36,7 +36,7 @@ where
|
||||
impl<S, T> Future for Transport<S, T>
|
||||
where
|
||||
T: AsyncRead + AsyncWrite,
|
||||
S: Service<Frame, Response = Message>,
|
||||
S: Service<Request = Frame, Response = Message>,
|
||||
S::Future: 'static,
|
||||
S::Error: 'static,
|
||||
{
|
||||
|
@ -56,7 +56,8 @@ impl TestServer {
|
||||
pub fn new<F: StreamServiceFactory>(
|
||||
factory: F,
|
||||
) -> TestServerRuntime<
|
||||
impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone,
|
||||
impl Service<Request = Connect, Response = impl Connection, Error = ConnectorError>
|
||||
+ Clone,
|
||||
> {
|
||||
let (tx, rx) = mpsc::channel();
|
||||
|
||||
@ -88,8 +89,11 @@ impl TestServer {
|
||||
}
|
||||
|
||||
fn new_connector(
|
||||
) -> impl Service<Connect, Response = impl Connection, Error = ConnectorError> + Clone
|
||||
{
|
||||
) -> impl Service<
|
||||
Request = Connect,
|
||||
Response = impl Connection,
|
||||
Error = ConnectorError,
|
||||
> + Clone {
|
||||
#[cfg(feature = "ssl")]
|
||||
{
|
||||
use openssl::ssl::{SslConnector, SslMethod, SslVerifyMode};
|
||||
@ -202,7 +206,7 @@ impl<T> TestServerRuntime<T> {
|
||||
|
||||
impl<T> TestServerRuntime<T>
|
||||
where
|
||||
T: Service<Connect, Error = ConnectorError> + Clone,
|
||||
T: Service<Request = Connect, Error = ConnectorError> + Clone,
|
||||
T::Response: Connection,
|
||||
{
|
||||
/// Connect to websocket server at a given path
|
||||
|
@ -565,17 +565,22 @@ fn test_body_chunked_implicit() {
|
||||
assert_eq!(bytes, Bytes::from_static(STR.as_ref()));
|
||||
}
|
||||
|
||||
use actix_server_config::ServerConfig;
|
||||
use actix_service::fn_cfg_factory;
|
||||
|
||||
#[test]
|
||||
fn test_response_http_error_handling() {
|
||||
let mut srv = TestServer::new(|| {
|
||||
h1::H1Service::new(|_| {
|
||||
let broken_header = Bytes::from_static(b"\0\0\0");
|
||||
ok::<_, ()>(
|
||||
Response::Ok()
|
||||
.header(http::header::CONTENT_TYPE, broken_header)
|
||||
.body(STR),
|
||||
)
|
||||
})
|
||||
h1::H1Service::new(fn_cfg_factory(|_: &ServerConfig| {
|
||||
Ok::<_, ()>(|_| {
|
||||
let broken_header = Bytes::from_static(b"\0\0\0");
|
||||
ok::<_, ()>(
|
||||
Response::Ok()
|
||||
.header(http::header::CONTENT_TYPE, broken_header)
|
||||
.body(STR),
|
||||
)
|
||||
})
|
||||
}))
|
||||
});
|
||||
|
||||
let req = srv.get().finish().unwrap();
|
||||
|
Loading…
Reference in New Issue
Block a user