1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-06-11 01:39:33 +00:00

update actix-service

This commit is contained in:
Nikolay Kim 2019-03-05 10:08:08 -08:00
parent b6fe1dacf2
commit 03248028a9
11 changed files with 132 additions and 159 deletions

View file

@ -31,7 +31,7 @@ members = [
]
[package.metadata.docs.rs]
features = ["ssl", "tls", "rust-tls"]
features = ["ssl", "tls", "rust-tls"] #, "session"]
[features]
default = ["brotli", "flate2-c"]
@ -45,6 +45,9 @@ flate2-c = ["flate2/miniz-sys"]
# rust backend for flate2 crate
flate2-rust = ["flate2/rust_backend"]
# sessions feature, session require "ring" crate and c compiler
# session = ["actix-session"]
# tls
tls = ["native-tls", "actix-server/ssl"]
@ -56,10 +59,13 @@ ssl = ["openssl", "actix-server/ssl"]
[dependencies]
actix-codec = "0.1.0"
actix-service = "0.3.2"
actix-utils = "0.3.1"
#actix-service = "0.3.2"
#actix-utils = "0.3.1"
actix-rt = "0.1.0"
actix-service = { git = "https://github.com/actix/actix-net.git" }
actix-utils = { git = "https://github.com/actix/actix-net.git" }
actix-http = { git = "https://github.com/actix/actix-http.git" }
actix-router = { git = "https://github.com/actix/actix-net.git" }
actix-server = { git = "https://github.com/actix/actix-net.git" }
@ -79,6 +85,9 @@ serde_json = "1.0"
serde_urlencoded = "^0.5.3"
threadpool = "1.7"
# middlewares
# actix-session = { path="session", optional = true }
# compression
brotli2 = { version="^0.3.2", optional = true }
flate2 = { version="^1.0.2", optional = true, default-features = false }

View file

@ -25,7 +25,7 @@ type HttpNewService<P> = BoxedNewService<(), ServiceRequest<P>, ServiceResponse,
type BoxedResponse = Box<Future<Item = ServiceResponse, Error = ()>>;
pub trait HttpServiceFactory<Request> {
type Factory: NewService<Request = Request>;
type Factory: NewService<Request>;
fn rdef(&self) -> &ResourceDef;
@ -36,7 +36,7 @@ pub trait HttpServiceFactory<Request> {
/// for building application instances.
pub struct App<P, T>
where
T: NewService<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,
T: NewService<ServiceRequest, Response = ServiceRequest<P>>,
{
chain: T,
extensions: Extensions,
@ -61,7 +61,7 @@ impl<P, T> App<P, T>
where
P: 'static,
T: NewService<
Request = ServiceRequest<PayloadStream>,
ServiceRequest,
Response = ServiceRequest<P>,
Error = (),
InitError = (),
@ -197,7 +197,7 @@ where
where
F: FnOnce(Resource<P>) -> Resource<P, U>,
U: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -230,7 +230,7 @@ where
P,
B,
impl NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse<B>,
Error = (),
InitError = (),
@ -239,12 +239,12 @@ where
where
M: Transform<
AppRouting<P>,
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse<B>,
Error = (),
InitError = (),
>,
F: IntoTransform<M, AppRouting<P>>,
F: IntoTransform<M, AppRouting<P>, ServiceRequest<P>>,
{
let fref = Rc::new(RefCell::new(None));
let endpoint = ApplyTransform::new(mw, AppEntry::new(fref.clone()));
@ -269,7 +269,7 @@ where
) -> App<
P1,
impl NewService<
Request = ServiceRequest<PayloadStream>,
ServiceRequest,
Response = ServiceRequest<P1>,
Error = (),
InitError = (),
@ -277,13 +277,12 @@ where
>
where
C: NewService<
(),
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceRequest<P1>,
Error = (),
InitError = (),
>,
F: IntoNewService<C>,
F: IntoNewService<C, ServiceRequest<P>>,
{
let chain = self.chain.and_then(chain.into_new_service());
App {
@ -326,7 +325,7 @@ where
P: 'static,
B: MessageBody,
T: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse<B>,
Error = (),
InitError = (),
@ -406,7 +405,7 @@ where
where
F: FnOnce(Resource<P>) -> Resource<P, U>,
U: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -430,12 +429,9 @@ where
pub fn default_resource<F, R, U>(mut self, f: F) -> Self
where
F: FnOnce(Resource<P>) -> R,
R: IntoNewService<U>,
U: NewService<
Request = ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
> + 'static,
R: IntoNewService<U, ServiceRequest<P>>,
U: NewService<ServiceRequest<P>, Response = ServiceResponse, Error = ()>
+ 'static,
{
// create and configure default resource
self.default = Some(Rc::new(boxed::new_service(
@ -449,12 +445,9 @@ where
pub fn service<R, F, U>(mut self, rdef: R, factory: F) -> Self
where
R: Into<ResourceDef>,
F: IntoNewService<U>,
U: NewService<
Request = ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
> + 'static,
F: IntoNewService<U, ServiceRequest<P>>,
U: NewService<ServiceRequest<P>, Response = ServiceResponse, Error = ()>
+ 'static,
{
self.services.push((
rdef.into(),
@ -473,7 +466,7 @@ where
P,
B1,
impl NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse<B1>,
Error = (),
InitError = (),
@ -482,13 +475,13 @@ where
where
M: Transform<
T::Service,
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse<B1>,
Error = (),
InitError = (),
>,
B1: MessageBody,
F: IntoTransform<M, T::Service>,
F: IntoTransform<M, T::Service, ServiceRequest<P>>,
{
let endpoint = ApplyTransform::new(mw, self.endpoint);
AppRouter {
@ -542,22 +535,23 @@ where
}
impl<C, T, P: 'static, B: MessageBody>
IntoNewService<AndThenNewService<AppInit<C, P>, T, ()>> for AppRouter<C, P, B, T>
IntoNewService<AndThenNewService<AppInit<C, P>, T>, Request>
for AppRouter<C, P, B, T>
where
T: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse<B>,
Error = (),
InitError = (),
>,
C: NewService<
Request = ServiceRequest<PayloadStream>,
ServiceRequest,
Response = ServiceRequest<P>,
Error = (),
InitError = (),
>,
{
fn into_new_service(self) -> AndThenNewService<AppInit<C, P>, T, ()> {
fn into_new_service(self) -> AndThenNewService<AppInit<C, P>, T> {
// update resource default service
if self.default.is_some() {
for default in &self.defaults {
@ -592,8 +586,7 @@ pub struct AppRoutingFactory<P> {
default: Option<Rc<HttpNewService<P>>>,
}
impl<P: 'static> NewService for AppRoutingFactory<P> {
type Request = ServiceRequest<P>;
impl<P: 'static> NewService<ServiceRequest<P>> for AppRoutingFactory<P> {
type Response = ServiceResponse;
type Error = ();
type InitError = ();
@ -709,8 +702,7 @@ pub struct AppRouting<P> {
default: Option<HttpService<P>>,
}
impl<P> Service for AppRouting<P> {
type Request = ServiceRequest<P>;
impl<P> Service<ServiceRequest<P>> for AppRouting<P> {
type Response = ServiceResponse;
type Error = ();
type Future = Either<BoxedResponse, FutureResult<Self::Response, Self::Error>>;
@ -758,8 +750,7 @@ impl<P> AppEntry<P> {
}
}
impl<P: 'static> NewService for AppEntry<P> {
type Request = ServiceRequest<P>;
impl<P: 'static> NewService<ServiceRequest<P>> for AppEntry<P> {
type Response = ServiceResponse;
type Error = ();
type InitError = ();
@ -774,9 +765,8 @@ impl<P: 'static> NewService for AppEntry<P> {
#[doc(hidden)]
pub struct AppChain;
impl NewService<()> for AppChain {
type Request = ServiceRequest<PayloadStream>;
type Response = ServiceRequest<PayloadStream>;
impl NewService<ServiceRequest> for AppChain {
type Response = ServiceRequest;
type Error = ();
type InitError = ();
type Service = AppChain;
@ -787,9 +777,8 @@ impl NewService<()> for AppChain {
}
}
impl Service for AppChain {
type Request = ServiceRequest<PayloadStream>;
type Response = ServiceRequest<PayloadStream>;
impl Service<ServiceRequest> for AppChain {
type Response = ServiceRequest;
type Error = ();
type Future = FutureResult<Self::Response, Self::Error>;
@ -799,7 +788,7 @@ impl Service for AppChain {
}
#[inline]
fn call(&mut self, req: Self::Request) -> Self::Future {
fn call(&mut self, req: ServiceRequest) -> Self::Future {
ok(req)
}
}
@ -808,22 +797,17 @@ impl Service for AppChain {
/// It also executes state factories.
pub struct AppInit<C, P>
where
C: NewService<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,
C: NewService<ServiceRequest, Response = ServiceRequest<P>>,
{
chain: C,
state: Vec<Box<StateFactory>>,
extensions: Rc<RefCell<Rc<Extensions>>>,
}
impl<C, P: 'static> NewService for AppInit<C, P>
impl<C, P: 'static> NewService<Request> for AppInit<C, P>
where
C: NewService<
Request = ServiceRequest<PayloadStream>,
Response = ServiceRequest<P>,
InitError = (),
>,
C: NewService<ServiceRequest, Response = ServiceRequest<P>, InitError = ()>,
{
type Request = Request<PayloadStream>;
type Response = ServiceRequest<P>;
type Error = C::Error;
type InitError = C::InitError;
@ -842,11 +826,7 @@ where
#[doc(hidden)]
pub struct AppInitResult<C, P>
where
C: NewService<
Request = ServiceRequest<PayloadStream>,
Response = ServiceRequest<P>,
InitError = (),
>,
C: NewService<ServiceRequest, Response = ServiceRequest<P>, InitError = ()>,
{
chain: C::Future,
state: Vec<Box<StateFactoryResult>>,
@ -855,11 +835,7 @@ where
impl<C, P> Future for AppInitResult<C, P>
where
C: NewService<
Request = ServiceRequest<PayloadStream>,
Response = ServiceRequest<P>,
InitError = (),
>,
C: NewService<ServiceRequest, Response = ServiceRequest<P>, InitError = ()>,
{
type Item = AppInitService<C::Service, P>;
type Error = C::InitError;
@ -893,17 +869,16 @@ where
/// Service to convert `Request` to a `ServiceRequest<S>`
pub struct AppInitService<C, P>
where
C: Service<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,
C: Service<ServiceRequest, Response = ServiceRequest<P>>,
{
chain: C,
extensions: Rc<Extensions>,
}
impl<C, P> Service for AppInitService<C, P>
impl<C, P> Service<Request> for AppInitService<C, P>
where
C: Service<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,
C: Service<ServiceRequest, Response = ServiceRequest<P>>,
{
type Request = Request<PayloadStream>;
type Response = ServiceRequest<P>;
type Error = C::Error;
type Future = C::Future;
@ -912,7 +887,7 @@ where
self.chain.poll_ready()
}
fn call(&mut self, req: Request<PayloadStream>) -> Self::Future {
fn call(&mut self, req: Request) -> Self::Future {
let req = ServiceRequest::new(
Path::new(Url::new(req.uri().clone())),
req,

View file

@ -52,12 +52,11 @@ where
}
}
}
impl<F, T, R> NewService for Handle<F, T, R>
impl<F, T, R> NewService<(T, HttpRequest)> for Handle<F, T, R>
where
F: Factory<T, R>,
R: Responder + 'static,
{
type Request = (T, HttpRequest);
type Response = ServiceResponse;
type Error = Void;
type InitError = ();
@ -82,12 +81,11 @@ where
_t: PhantomData<(T, R)>,
}
impl<F, T, R> Service for HandleService<F, T, R>
impl<F, T, R> Service<(T, HttpRequest)> for HandleService<F, T, R>
where
F: Factory<T, R>,
R: Responder + 'static,
{
type Request = (T, HttpRequest);
type Response = ServiceResponse;
type Error = Void;
type Future = HandleServiceResponse<<R::Future as IntoFuture>::Future>;
@ -184,14 +182,13 @@ where
}
}
}
impl<F, T, R> NewService for AsyncHandle<F, T, R>
impl<F, T, R> NewService<(T, HttpRequest)> for AsyncHandle<F, T, R>
where
F: AsyncFactory<T, R>,
R: IntoFuture,
R::Item: Into<Response>,
R::Error: Into<Error>,
{
type Request = (T, HttpRequest);
type Response = ServiceResponse;
type Error = ();
type InitError = ();
@ -218,14 +215,13 @@ where
_t: PhantomData<(T, R)>,
}
impl<F, T, R> Service for AsyncHandleService<F, T, R>
impl<F, T, R> Service<(T, HttpRequest)> for AsyncHandleService<F, T, R>
where
F: AsyncFactory<T, R>,
R: IntoFuture,
R::Item: Into<Response>,
R::Error: Into<Error>,
{
type Request = (T, HttpRequest);
type Response = ServiceResponse;
type Error = ();
type Future = AsyncHandleServiceResponse<R::Future>;
@ -290,8 +286,7 @@ impl<P, T: FromRequest<P>> Extract<P, T> {
}
}
impl<P, T: FromRequest<P>> NewService for Extract<P, T> {
type Request = ServiceRequest<P>;
impl<P, T: FromRequest<P>> NewService<ServiceRequest<P>> for Extract<P, T> {
type Response = (T, HttpRequest);
type Error = (Error, ServiceFromRequest<P>);
type InitError = ();
@ -311,8 +306,7 @@ pub struct ExtractService<P, T: FromRequest<P>> {
_t: PhantomData<(P, T)>,
}
impl<P, T: FromRequest<P>> Service for ExtractService<P, T> {
type Request = ServiceRequest<P>;
impl<P, T: FromRequest<P>> Service<ServiceRequest<P>> for ExtractService<P, T> {
type Response = (T, HttpRequest);
type Error = (Error, ServiceFromRequest<P>);
type Future = ExtractResponse<P, T>;

View file

@ -36,14 +36,13 @@ impl Default for Compress {
}
}
impl<S, P, B> Transform<S> for Compress
impl<S, P, B> Transform<S, ServiceRequest<P>> for Compress
where
P: 'static,
B: MessageBody,
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
S::Future: 'static,
{
type Request = ServiceRequest<P>;
type Response = ServiceResponse<Encoder<B>>;
type Error = S::Error;
type InitError = ();
@ -63,14 +62,13 @@ pub struct CompressMiddleware<S> {
encoding: ContentEncoding,
}
impl<S, P, B> Service for CompressMiddleware<S>
impl<S, P, B> Service<ServiceRequest<P>> for CompressMiddleware<S>
where
P: 'static,
B: MessageBody,
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
S::Future: 'static,
{
type Request = ServiceRequest<P>;
type Response = ServiceResponse<Encoder<B>>;
type Error = S::Error;
type Future = CompressResponse<S, P, B>;
@ -103,7 +101,7 @@ pub struct CompressResponse<S, P, B>
where
P: 'static,
B: MessageBody,
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
S::Future: 'static,
{
fut: S::Future,
@ -114,7 +112,7 @@ impl<S, P, B> Future for CompressResponse<S, P, B>
where
P: 'static,
B: MessageBody,
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
S::Future: 'static,
{
type Item = ServiceResponse<Encoder<B>>;

View file

@ -84,12 +84,11 @@ impl DefaultHeaders {
}
}
impl<S, P, B> Transform<S> for DefaultHeaders
impl<S, P, B> Transform<S, ServiceRequest<P>> for DefaultHeaders
where
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
S::Future: 'static,
{
type Request = ServiceRequest<P>;
type Response = ServiceResponse<B>;
type Error = S::Error;
type InitError = ();
@ -109,12 +108,11 @@ pub struct DefaultHeadersMiddleware<S> {
inner: Rc<Inner>,
}
impl<S, P, B> Service for DefaultHeadersMiddleware<S>
impl<S, P, B> Service<ServiceRequest<P>> for DefaultHeadersMiddleware<S>
where
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
S::Future: 'static,
{
type Request = ServiceRequest<P>;
type Response = ServiceResponse<B>;
type Error = S::Error;
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;

View file

@ -5,3 +5,6 @@ pub use self::compress::Compress;
mod defaultheaders;
pub use self::defaultheaders::DefaultHeaders;
#[cfg(feature = "session")]
pub use actix_session as session;

View file

@ -65,7 +65,7 @@ impl<P> Default for Resource<P> {
impl<P: 'static, T> Resource<P, T>
where
T: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -187,7 +187,7 @@ where
) -> Resource<
P,
impl NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -196,12 +196,12 @@ where
where
M: Transform<
T::Service,
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
>,
F: IntoTransform<M, T::Service>,
F: IntoTransform<M, T::Service, ServiceRequest<P>>,
{
let endpoint = ApplyTransform::new(mw, self.endpoint);
Resource {
@ -216,12 +216,9 @@ where
pub fn default_resource<F, R, U>(mut self, f: F) -> Self
where
F: FnOnce(Resource<P>) -> R,
R: IntoNewService<U>,
U: NewService<
Request = ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
> + 'static,
R: IntoNewService<U, ServiceRequest<P>>,
U: NewService<ServiceRequest<P>, Response = ServiceResponse, Error = ()>
+ 'static,
{
// create and configure default resource
self.default = Rc::new(RefCell::new(Some(Rc::new(boxed::new_service(
@ -236,10 +233,10 @@ where
}
}
impl<P, T> IntoNewService<T> for Resource<P, T>
impl<P, T> IntoNewService<T, ServiceRequest<P>> for Resource<P, T>
where
T: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -260,8 +257,7 @@ pub struct ResourceFactory<P> {
default: Rc<RefCell<Option<Rc<HttpNewService<P>>>>>,
}
impl<P: 'static> NewService for ResourceFactory<P> {
type Request = ServiceRequest<P>;
impl<P: 'static> NewService<ServiceRequest<P>> for ResourceFactory<P> {
type Response = ServiceResponse;
type Error = ();
type InitError = ();
@ -351,8 +347,7 @@ pub struct ResourceService<P> {
default: Option<HttpService<P>>,
}
impl<P> Service for ResourceService<P> {
type Request = ServiceRequest<P>;
impl<P> Service<ServiceRequest<P>> for ResourceService<P> {
type Response = ServiceResponse;
type Error = ();
type Future = Either<
@ -396,8 +391,7 @@ impl<P> ResourceEndpoint<P> {
}
}
impl<P: 'static> NewService for ResourceEndpoint<P> {
type Request = ServiceRequest<P>;
impl<P: 'static> NewService<ServiceRequest<P>> for ResourceEndpoint<P> {
type Response = ServiceResponse;
type Error = ();
type InitError = ();

View file

@ -1,4 +1,5 @@
use std::cell::RefCell;
use std::marker::PhantomData;
use std::rc::Rc;
use actix_http::{http::Method, Error, Extensions, Response};
@ -14,7 +15,7 @@ use crate::HttpResponse;
type BoxedRouteService<Req, Res> = Box<
Service<
Request = Req,
Req,
Response = Res,
Error = (),
Future = Box<Future<Item = Res, Error = ()>>,
@ -23,7 +24,7 @@ type BoxedRouteService<Req, Res> = Box<
type BoxedRouteNewService<Req, Res> = Box<
NewService<
Request = Req,
Req,
Response = Res,
Error = (),
InitError = (),
@ -85,8 +86,7 @@ impl<P: 'static> Route<P> {
}
}
impl<P> NewService for Route<P> {
type Request = ServiceRequest<P>;
impl<P> NewService<ServiceRequest<P>> for Route<P> {
type Response = ServiceResponse;
type Error = ();
type InitError = ();
@ -141,8 +141,7 @@ impl<P> RouteService<P> {
}
}
impl<P> Service for RouteService<P> {
type Request = ServiceRequest<P>;
impl<P> Service<ServiceRequest<P>> for RouteService<P> {
type Response = ServiceResponse;
type Error = ();
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
@ -151,7 +150,7 @@ impl<P> Service for RouteService<P> {
self.service.poll_ready()
}
fn call(&mut self, req: Self::Request) -> Self::Future {
fn call(&mut self, req: ServiceRequest<P>) -> Self::Future {
self.service.call(req)
}
}
@ -348,43 +347,46 @@ impl<P: 'static> Route<P> {
struct RouteNewService<P, T>
where
T: NewService<Request = ServiceRequest<P>, Error = (Error, ServiceFromRequest<P>)>,
T: NewService<ServiceRequest<P>, Error = (Error, ServiceFromRequest<P>)>,
{
service: T,
_t: PhantomData<P>,
}
impl<P: 'static, T> RouteNewService<P, T>
where
T: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (Error, ServiceFromRequest<P>),
>,
T::Future: 'static,
T::Service: 'static,
<T::Service as Service>::Future: 'static,
<T::Service as Service<ServiceRequest<P>>>::Future: 'static,
{
pub fn new(service: T) -> Self {
RouteNewService { service }
RouteNewService {
service,
_t: PhantomData,
}
}
}
impl<P: 'static, T> NewService for RouteNewService<P, T>
impl<P: 'static, T> NewService<ServiceRequest<P>> for RouteNewService<P, T>
where
T: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (Error, ServiceFromRequest<P>),
>,
T::Future: 'static,
T::Service: 'static,
<T::Service as Service>::Future: 'static,
<T::Service as Service<ServiceRequest<P>>>::Future: 'static,
{
type Request = ServiceRequest<P>;
type Response = ServiceResponse;
type Error = ();
type InitError = ();
type Service = BoxedRouteService<Self::Request, Self::Response>;
type Service = BoxedRouteService<ServiceRequest<P>, Self::Response>;
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>;
fn new_service(&self, _: &()) -> Self::Future {
@ -394,27 +396,30 @@ where
.map_err(|_| ())
.and_then(|service| {
let service: BoxedRouteService<_, _> =
Box::new(RouteServiceWrapper { service });
Box::new(RouteServiceWrapper {
service,
_t: PhantomData,
});
Ok(service)
}),
)
}
}
struct RouteServiceWrapper<P, T: Service<Request = ServiceRequest<P>>> {
struct RouteServiceWrapper<P, T: Service<ServiceRequest<P>>> {
service: T,
_t: PhantomData<P>,
}
impl<P, T> Service for RouteServiceWrapper<P, T>
impl<P, T> Service<ServiceRequest<P>> for RouteServiceWrapper<P, T>
where
T::Future: 'static,
T: Service<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (Error, ServiceFromRequest<P>),
>,
{
type Request = ServiceRequest<P>;
type Response = ServiceResponse;
type Error = ();
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;

View file

@ -79,7 +79,7 @@ impl<P: 'static> Scope<P> {
impl<P: 'static, T> Scope<P, T>
where
T: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -196,7 +196,7 @@ where
where
F: FnOnce(Resource<P>) -> Resource<P, U>,
U: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -219,7 +219,7 @@ where
where
F: FnOnce(Resource<P>) -> Resource<P, U>,
U: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -244,7 +244,7 @@ where
) -> Scope<
P,
impl NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -253,12 +253,12 @@ where
where
M: Transform<
T::Service,
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
>,
F: IntoTransform<M, T::Service>,
F: IntoTransform<M, T::Service, ServiceRequest<P>>,
{
let endpoint = ApplyTransform::new(mw, self.endpoint);
Scope {
@ -293,10 +293,10 @@ pub(crate) fn insert_slash(path: &str) -> String {
path
}
impl<P, T> IntoNewService<T> for Scope<P, T>
impl<P, T> IntoNewService<T, ServiceRequest<P>> for Scope<P, T>
where
T: NewService<
Request = ServiceRequest<P>,
ServiceRequest<P>,
Response = ServiceResponse,
Error = (),
InitError = (),
@ -331,8 +331,7 @@ pub struct ScopeFactory<P> {
default: Rc<RefCell<Option<Rc<HttpNewService<P>>>>>,
}
impl<P: 'static> NewService for ScopeFactory<P> {
type Request = ServiceRequest<P>;
impl<P: 'static> NewService<ServiceRequest<P>> for ScopeFactory<P> {
type Response = ServiceResponse;
type Error = ();
type InitError = ();
@ -448,8 +447,7 @@ pub struct ScopeService<P> {
_ready: Option<(ServiceRequest<P>, ResourceInfo)>,
}
impl<P> Service for ScopeService<P> {
type Request = ServiceRequest<P>;
impl<P> Service<ServiceRequest<P>> for ScopeService<P> {
type Response = ServiceResponse;
type Error = ();
type Future = Either<BoxedResponse, FutureResult<Self::Response, Self::Error>>;
@ -492,8 +490,7 @@ impl<P> ScopeEndpoint<P> {
}
}
impl<P: 'static> NewService for ScopeEndpoint<P> {
type Request = ServiceRequest<P>;
impl<P: 'static> NewService<ServiceRequest<P>> for ScopeEndpoint<P> {
type Response = ServiceResponse;
type Error = ();
type InitError = ();

View file

@ -52,8 +52,8 @@ struct Config {
pub struct HttpServer<F, I, S, B>
where
F: Fn() -> I + Send + Clone + 'static,
I: IntoNewService<S>,
S: NewService<Request = Request>,
I: IntoNewService<S, Request>,
S: NewService<Request>,
S::Error: fmt::Debug,
S::Response: Into<Response<B>>,
S::Service: 'static,
@ -71,8 +71,8 @@ where
impl<F, I, S, B> HttpServer<F, I, S, B>
where
F: Fn() -> I + Send + Clone + 'static,
I: IntoNewService<S>,
S: NewService<Request = Request>,
I: IntoNewService<S, Request>,
S: NewService<Request>,
S::Error: fmt::Debug,
S::Response: Into<Response<B>>,
S::Service: 'static,
@ -431,8 +431,8 @@ where
impl<F, I, S, B> HttpServer<F, I, S, B>
where
F: Fn() -> I + Send + Clone + 'static,
I: IntoNewService<S>,
S: NewService<Request = Request>,
I: IntoNewService<S, Request>,
S: NewService<Request>,
S::Error: fmt::Debug,
S::Response: Into<Response<B>>,
S::Service: 'static,

View file

@ -5,15 +5,15 @@ use std::rc::Rc;
use actix_http::body::{Body, MessageBody, ResponseBody};
use actix_http::http::{HeaderMap, Method, Uri, Version};
use actix_http::{
Error, Extensions, HttpMessage, Payload, Request, RequestHead, Response,
ResponseHead,
Error, Extensions, HttpMessage, Payload, PayloadStream, Request, RequestHead,
Response, ResponseHead,
};
use actix_router::{Path, Resource, Url};
use futures::future::{ok, FutureResult, IntoFuture};
use crate::request::HttpRequest;
pub struct ServiceRequest<P> {
pub struct ServiceRequest<P = PayloadStream> {
req: HttpRequest,
payload: Payload<P>,
}