mirror of
https://github.com/actix/actix-extras.git
synced 2024-11-28 01:32:57 +01:00
update actix-service
This commit is contained in:
parent
b6fe1dacf2
commit
03248028a9
15
Cargo.toml
15
Cargo.toml
@ -31,7 +31,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
features = ["ssl", "tls", "rust-tls"]
|
features = ["ssl", "tls", "rust-tls"] #, "session"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["brotli", "flate2-c"]
|
default = ["brotli", "flate2-c"]
|
||||||
@ -45,6 +45,9 @@ flate2-c = ["flate2/miniz-sys"]
|
|||||||
# rust backend for flate2 crate
|
# rust backend for flate2 crate
|
||||||
flate2-rust = ["flate2/rust_backend"]
|
flate2-rust = ["flate2/rust_backend"]
|
||||||
|
|
||||||
|
# sessions feature, session require "ring" crate and c compiler
|
||||||
|
# session = ["actix-session"]
|
||||||
|
|
||||||
# tls
|
# tls
|
||||||
tls = ["native-tls", "actix-server/ssl"]
|
tls = ["native-tls", "actix-server/ssl"]
|
||||||
|
|
||||||
@ -56,10 +59,13 @@ ssl = ["openssl", "actix-server/ssl"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
actix-codec = "0.1.0"
|
actix-codec = "0.1.0"
|
||||||
actix-service = "0.3.2"
|
#actix-service = "0.3.2"
|
||||||
actix-utils = "0.3.1"
|
#actix-utils = "0.3.1"
|
||||||
actix-rt = "0.1.0"
|
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-http = { git = "https://github.com/actix/actix-http.git" }
|
||||||
actix-router = { git = "https://github.com/actix/actix-net.git" }
|
actix-router = { git = "https://github.com/actix/actix-net.git" }
|
||||||
actix-server = { 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"
|
serde_urlencoded = "^0.5.3"
|
||||||
threadpool = "1.7"
|
threadpool = "1.7"
|
||||||
|
|
||||||
|
# middlewares
|
||||||
|
# actix-session = { path="session", optional = true }
|
||||||
|
|
||||||
# compression
|
# compression
|
||||||
brotli2 = { version="^0.3.2", optional = true }
|
brotli2 = { version="^0.3.2", optional = true }
|
||||||
flate2 = { version="^1.0.2", optional = true, default-features = false }
|
flate2 = { version="^1.0.2", optional = true, default-features = false }
|
||||||
|
111
src/app.rs
111
src/app.rs
@ -25,7 +25,7 @@ type HttpNewService<P> = BoxedNewService<(), ServiceRequest<P>, ServiceResponse,
|
|||||||
type BoxedResponse = Box<Future<Item = ServiceResponse, Error = ()>>;
|
type BoxedResponse = Box<Future<Item = ServiceResponse, Error = ()>>;
|
||||||
|
|
||||||
pub trait HttpServiceFactory<Request> {
|
pub trait HttpServiceFactory<Request> {
|
||||||
type Factory: NewService<Request = Request>;
|
type Factory: NewService<Request>;
|
||||||
|
|
||||||
fn rdef(&self) -> &ResourceDef;
|
fn rdef(&self) -> &ResourceDef;
|
||||||
|
|
||||||
@ -36,7 +36,7 @@ pub trait HttpServiceFactory<Request> {
|
|||||||
/// for building application instances.
|
/// for building application instances.
|
||||||
pub struct App<P, T>
|
pub struct App<P, T>
|
||||||
where
|
where
|
||||||
T: NewService<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,
|
T: NewService<ServiceRequest, Response = ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
chain: T,
|
chain: T,
|
||||||
extensions: Extensions,
|
extensions: Extensions,
|
||||||
@ -61,7 +61,7 @@ impl<P, T> App<P, T>
|
|||||||
where
|
where
|
||||||
P: 'static,
|
P: 'static,
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<PayloadStream>,
|
ServiceRequest,
|
||||||
Response = ServiceRequest<P>,
|
Response = ServiceRequest<P>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -197,7 +197,7 @@ where
|
|||||||
where
|
where
|
||||||
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
||||||
U: NewService<
|
U: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -230,7 +230,7 @@ where
|
|||||||
P,
|
P,
|
||||||
B,
|
B,
|
||||||
impl NewService<
|
impl NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse<B>,
|
Response = ServiceResponse<B>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -239,12 +239,12 @@ where
|
|||||||
where
|
where
|
||||||
M: Transform<
|
M: Transform<
|
||||||
AppRouting<P>,
|
AppRouting<P>,
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse<B>,
|
Response = ServiceResponse<B>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
>,
|
>,
|
||||||
F: IntoTransform<M, AppRouting<P>>,
|
F: IntoTransform<M, AppRouting<P>, ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
let fref = Rc::new(RefCell::new(None));
|
let fref = Rc::new(RefCell::new(None));
|
||||||
let endpoint = ApplyTransform::new(mw, AppEntry::new(fref.clone()));
|
let endpoint = ApplyTransform::new(mw, AppEntry::new(fref.clone()));
|
||||||
@ -269,7 +269,7 @@ where
|
|||||||
) -> App<
|
) -> App<
|
||||||
P1,
|
P1,
|
||||||
impl NewService<
|
impl NewService<
|
||||||
Request = ServiceRequest<PayloadStream>,
|
ServiceRequest,
|
||||||
Response = ServiceRequest<P1>,
|
Response = ServiceRequest<P1>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -277,13 +277,12 @@ where
|
|||||||
>
|
>
|
||||||
where
|
where
|
||||||
C: NewService<
|
C: NewService<
|
||||||
(),
|
ServiceRequest<P>,
|
||||||
Request = ServiceRequest<P>,
|
|
||||||
Response = ServiceRequest<P1>,
|
Response = ServiceRequest<P1>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
>,
|
>,
|
||||||
F: IntoNewService<C>,
|
F: IntoNewService<C, ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
let chain = self.chain.and_then(chain.into_new_service());
|
let chain = self.chain.and_then(chain.into_new_service());
|
||||||
App {
|
App {
|
||||||
@ -326,7 +325,7 @@ where
|
|||||||
P: 'static,
|
P: 'static,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse<B>,
|
Response = ServiceResponse<B>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -406,7 +405,7 @@ where
|
|||||||
where
|
where
|
||||||
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
||||||
U: NewService<
|
U: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -430,12 +429,9 @@ where
|
|||||||
pub fn default_resource<F, R, U>(mut self, f: F) -> Self
|
pub fn default_resource<F, R, U>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: FnOnce(Resource<P>) -> R,
|
F: FnOnce(Resource<P>) -> R,
|
||||||
R: IntoNewService<U>,
|
R: IntoNewService<U, ServiceRequest<P>>,
|
||||||
U: NewService<
|
U: NewService<ServiceRequest<P>, Response = ServiceResponse, Error = ()>
|
||||||
Request = ServiceRequest<P>,
|
+ 'static,
|
||||||
Response = ServiceResponse,
|
|
||||||
Error = (),
|
|
||||||
> + 'static,
|
|
||||||
{
|
{
|
||||||
// create and configure default resource
|
// create and configure default resource
|
||||||
self.default = Some(Rc::new(boxed::new_service(
|
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
|
pub fn service<R, F, U>(mut self, rdef: R, factory: F) -> Self
|
||||||
where
|
where
|
||||||
R: Into<ResourceDef>,
|
R: Into<ResourceDef>,
|
||||||
F: IntoNewService<U>,
|
F: IntoNewService<U, ServiceRequest<P>>,
|
||||||
U: NewService<
|
U: NewService<ServiceRequest<P>, Response = ServiceResponse, Error = ()>
|
||||||
Request = ServiceRequest<P>,
|
+ 'static,
|
||||||
Response = ServiceResponse,
|
|
||||||
Error = (),
|
|
||||||
> + 'static,
|
|
||||||
{
|
{
|
||||||
self.services.push((
|
self.services.push((
|
||||||
rdef.into(),
|
rdef.into(),
|
||||||
@ -473,7 +466,7 @@ where
|
|||||||
P,
|
P,
|
||||||
B1,
|
B1,
|
||||||
impl NewService<
|
impl NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse<B1>,
|
Response = ServiceResponse<B1>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -482,13 +475,13 @@ where
|
|||||||
where
|
where
|
||||||
M: Transform<
|
M: Transform<
|
||||||
T::Service,
|
T::Service,
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse<B1>,
|
Response = ServiceResponse<B1>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
>,
|
>,
|
||||||
B1: MessageBody,
|
B1: MessageBody,
|
||||||
F: IntoTransform<M, T::Service>,
|
F: IntoTransform<M, T::Service, ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
let endpoint = ApplyTransform::new(mw, self.endpoint);
|
let endpoint = ApplyTransform::new(mw, self.endpoint);
|
||||||
AppRouter {
|
AppRouter {
|
||||||
@ -542,22 +535,23 @@ where
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<C, T, P: 'static, B: MessageBody>
|
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
|
where
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse<B>,
|
Response = ServiceResponse<B>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
>,
|
>,
|
||||||
C: NewService<
|
C: NewService<
|
||||||
Request = ServiceRequest<PayloadStream>,
|
ServiceRequest,
|
||||||
Response = ServiceRequest<P>,
|
Response = ServiceRequest<P>,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
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
|
// update resource default service
|
||||||
if self.default.is_some() {
|
if self.default.is_some() {
|
||||||
for default in &self.defaults {
|
for default in &self.defaults {
|
||||||
@ -592,8 +586,7 @@ pub struct AppRoutingFactory<P> {
|
|||||||
default: Option<Rc<HttpNewService<P>>>,
|
default: Option<Rc<HttpNewService<P>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: 'static> NewService for AppRoutingFactory<P> {
|
impl<P: 'static> NewService<ServiceRequest<P>> for AppRoutingFactory<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -709,8 +702,7 @@ pub struct AppRouting<P> {
|
|||||||
default: Option<HttpService<P>>,
|
default: Option<HttpService<P>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> Service for AppRouting<P> {
|
impl<P> Service<ServiceRequest<P>> for AppRouting<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = Either<BoxedResponse, FutureResult<Self::Response, Self::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> {
|
impl<P: 'static> NewService<ServiceRequest<P>> for AppEntry<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -774,9 +765,8 @@ impl<P: 'static> NewService for AppEntry<P> {
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct AppChain;
|
pub struct AppChain;
|
||||||
|
|
||||||
impl NewService<()> for AppChain {
|
impl NewService<ServiceRequest> for AppChain {
|
||||||
type Request = ServiceRequest<PayloadStream>;
|
type Response = ServiceRequest;
|
||||||
type Response = ServiceRequest<PayloadStream>;
|
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Service = AppChain;
|
type Service = AppChain;
|
||||||
@ -787,9 +777,8 @@ impl NewService<()> for AppChain {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Service for AppChain {
|
impl Service<ServiceRequest> for AppChain {
|
||||||
type Request = ServiceRequest<PayloadStream>;
|
type Response = ServiceRequest;
|
||||||
type Response = ServiceRequest<PayloadStream>;
|
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = FutureResult<Self::Response, Self::Error>;
|
type Future = FutureResult<Self::Response, Self::Error>;
|
||||||
|
|
||||||
@ -799,7 +788,7 @@ impl Service for AppChain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn call(&mut self, req: Self::Request) -> Self::Future {
|
fn call(&mut self, req: ServiceRequest) -> Self::Future {
|
||||||
ok(req)
|
ok(req)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -808,22 +797,17 @@ impl Service for AppChain {
|
|||||||
/// It also executes state factories.
|
/// It also executes state factories.
|
||||||
pub struct AppInit<C, P>
|
pub struct AppInit<C, P>
|
||||||
where
|
where
|
||||||
C: NewService<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,
|
C: NewService<ServiceRequest, Response = ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
chain: C,
|
chain: C,
|
||||||
state: Vec<Box<StateFactory>>,
|
state: Vec<Box<StateFactory>>,
|
||||||
extensions: Rc<RefCell<Rc<Extensions>>>,
|
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
|
where
|
||||||
C: NewService<
|
C: NewService<ServiceRequest, Response = ServiceRequest<P>, InitError = ()>,
|
||||||
Request = ServiceRequest<PayloadStream>,
|
|
||||||
Response = ServiceRequest<P>,
|
|
||||||
InitError = (),
|
|
||||||
>,
|
|
||||||
{
|
{
|
||||||
type Request = Request<PayloadStream>;
|
|
||||||
type Response = ServiceRequest<P>;
|
type Response = ServiceRequest<P>;
|
||||||
type Error = C::Error;
|
type Error = C::Error;
|
||||||
type InitError = C::InitError;
|
type InitError = C::InitError;
|
||||||
@ -842,11 +826,7 @@ where
|
|||||||
#[doc(hidden)]
|
#[doc(hidden)]
|
||||||
pub struct AppInitResult<C, P>
|
pub struct AppInitResult<C, P>
|
||||||
where
|
where
|
||||||
C: NewService<
|
C: NewService<ServiceRequest, Response = ServiceRequest<P>, InitError = ()>,
|
||||||
Request = ServiceRequest<PayloadStream>,
|
|
||||||
Response = ServiceRequest<P>,
|
|
||||||
InitError = (),
|
|
||||||
>,
|
|
||||||
{
|
{
|
||||||
chain: C::Future,
|
chain: C::Future,
|
||||||
state: Vec<Box<StateFactoryResult>>,
|
state: Vec<Box<StateFactoryResult>>,
|
||||||
@ -855,11 +835,7 @@ where
|
|||||||
|
|
||||||
impl<C, P> Future for AppInitResult<C, P>
|
impl<C, P> Future for AppInitResult<C, P>
|
||||||
where
|
where
|
||||||
C: NewService<
|
C: NewService<ServiceRequest, Response = ServiceRequest<P>, InitError = ()>,
|
||||||
Request = ServiceRequest<PayloadStream>,
|
|
||||||
Response = ServiceRequest<P>,
|
|
||||||
InitError = (),
|
|
||||||
>,
|
|
||||||
{
|
{
|
||||||
type Item = AppInitService<C::Service, P>;
|
type Item = AppInitService<C::Service, P>;
|
||||||
type Error = C::InitError;
|
type Error = C::InitError;
|
||||||
@ -893,17 +869,16 @@ where
|
|||||||
/// Service to convert `Request` to a `ServiceRequest<S>`
|
/// Service to convert `Request` to a `ServiceRequest<S>`
|
||||||
pub struct AppInitService<C, P>
|
pub struct AppInitService<C, P>
|
||||||
where
|
where
|
||||||
C: Service<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,
|
C: Service<ServiceRequest, Response = ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
chain: C,
|
chain: C,
|
||||||
extensions: Rc<Extensions>,
|
extensions: Rc<Extensions>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<C, P> Service for AppInitService<C, P>
|
impl<C, P> Service<Request> for AppInitService<C, P>
|
||||||
where
|
where
|
||||||
C: Service<Request = ServiceRequest<PayloadStream>, Response = ServiceRequest<P>>,
|
C: Service<ServiceRequest, Response = ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
type Request = Request<PayloadStream>;
|
|
||||||
type Response = ServiceRequest<P>;
|
type Response = ServiceRequest<P>;
|
||||||
type Error = C::Error;
|
type Error = C::Error;
|
||||||
type Future = C::Future;
|
type Future = C::Future;
|
||||||
@ -912,7 +887,7 @@ where
|
|||||||
self.chain.poll_ready()
|
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(
|
let req = ServiceRequest::new(
|
||||||
Path::new(Url::new(req.uri().clone())),
|
Path::new(Url::new(req.uri().clone())),
|
||||||
req,
|
req,
|
||||||
|
@ -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
|
where
|
||||||
F: Factory<T, R>,
|
F: Factory<T, R>,
|
||||||
R: Responder + 'static,
|
R: Responder + 'static,
|
||||||
{
|
{
|
||||||
type Request = (T, HttpRequest);
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = Void;
|
type Error = Void;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -82,12 +81,11 @@ where
|
|||||||
_t: PhantomData<(T, R)>,
|
_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
|
where
|
||||||
F: Factory<T, R>,
|
F: Factory<T, R>,
|
||||||
R: Responder + 'static,
|
R: Responder + 'static,
|
||||||
{
|
{
|
||||||
type Request = (T, HttpRequest);
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = Void;
|
type Error = Void;
|
||||||
type Future = HandleServiceResponse<<R::Future as IntoFuture>::Future>;
|
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
|
where
|
||||||
F: AsyncFactory<T, R>,
|
F: AsyncFactory<T, R>,
|
||||||
R: IntoFuture,
|
R: IntoFuture,
|
||||||
R::Item: Into<Response>,
|
R::Item: Into<Response>,
|
||||||
R::Error: Into<Error>,
|
R::Error: Into<Error>,
|
||||||
{
|
{
|
||||||
type Request = (T, HttpRequest);
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -218,14 +215,13 @@ where
|
|||||||
_t: PhantomData<(T, R)>,
|
_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
|
where
|
||||||
F: AsyncFactory<T, R>,
|
F: AsyncFactory<T, R>,
|
||||||
R: IntoFuture,
|
R: IntoFuture,
|
||||||
R::Item: Into<Response>,
|
R::Item: Into<Response>,
|
||||||
R::Error: Into<Error>,
|
R::Error: Into<Error>,
|
||||||
{
|
{
|
||||||
type Request = (T, HttpRequest);
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = AsyncHandleServiceResponse<R::Future>;
|
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> {
|
impl<P, T: FromRequest<P>> NewService<ServiceRequest<P>> for Extract<P, T> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = (T, HttpRequest);
|
type Response = (T, HttpRequest);
|
||||||
type Error = (Error, ServiceFromRequest<P>);
|
type Error = (Error, ServiceFromRequest<P>);
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -311,8 +306,7 @@ pub struct ExtractService<P, T: FromRequest<P>> {
|
|||||||
_t: PhantomData<(P, T)>,
|
_t: PhantomData<(P, T)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P, T: FromRequest<P>> Service for ExtractService<P, T> {
|
impl<P, T: FromRequest<P>> Service<ServiceRequest<P>> for ExtractService<P, T> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = (T, HttpRequest);
|
type Response = (T, HttpRequest);
|
||||||
type Error = (Error, ServiceFromRequest<P>);
|
type Error = (Error, ServiceFromRequest<P>);
|
||||||
type Future = ExtractResponse<P, T>;
|
type Future = ExtractResponse<P, T>;
|
||||||
|
@ -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
|
where
|
||||||
P: 'static,
|
P: 'static,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse<Encoder<B>>;
|
type Response = ServiceResponse<Encoder<B>>;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -63,14 +62,13 @@ pub struct CompressMiddleware<S> {
|
|||||||
encoding: ContentEncoding,
|
encoding: ContentEncoding,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, P, B> Service for CompressMiddleware<S>
|
impl<S, P, B> Service<ServiceRequest<P>> for CompressMiddleware<S>
|
||||||
where
|
where
|
||||||
P: 'static,
|
P: 'static,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse<Encoder<B>>;
|
type Response = ServiceResponse<Encoder<B>>;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Future = CompressResponse<S, P, B>;
|
type Future = CompressResponse<S, P, B>;
|
||||||
@ -103,7 +101,7 @@ pub struct CompressResponse<S, P, B>
|
|||||||
where
|
where
|
||||||
P: 'static,
|
P: 'static,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
fut: S::Future,
|
fut: S::Future,
|
||||||
@ -114,7 +112,7 @@ impl<S, P, B> Future for CompressResponse<S, P, B>
|
|||||||
where
|
where
|
||||||
P: 'static,
|
P: 'static,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Item = ServiceResponse<Encoder<B>>;
|
type Item = ServiceResponse<Encoder<B>>;
|
||||||
|
@ -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
|
where
|
||||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -109,12 +108,11 @@ pub struct DefaultHeadersMiddleware<S> {
|
|||||||
inner: Rc<Inner>,
|
inner: Rc<Inner>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<S, P, B> Service for DefaultHeadersMiddleware<S>
|
impl<S, P, B> Service<ServiceRequest<P>> for DefaultHeadersMiddleware<S>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = S::Error;
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
@ -5,3 +5,6 @@ pub use self::compress::Compress;
|
|||||||
|
|
||||||
mod defaultheaders;
|
mod defaultheaders;
|
||||||
pub use self::defaultheaders::DefaultHeaders;
|
pub use self::defaultheaders::DefaultHeaders;
|
||||||
|
|
||||||
|
#[cfg(feature = "session")]
|
||||||
|
pub use actix_session as session;
|
||||||
|
@ -65,7 +65,7 @@ impl<P> Default for Resource<P> {
|
|||||||
impl<P: 'static, T> Resource<P, T>
|
impl<P: 'static, T> Resource<P, T>
|
||||||
where
|
where
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -187,7 +187,7 @@ where
|
|||||||
) -> Resource<
|
) -> Resource<
|
||||||
P,
|
P,
|
||||||
impl NewService<
|
impl NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -196,12 +196,12 @@ where
|
|||||||
where
|
where
|
||||||
M: Transform<
|
M: Transform<
|
||||||
T::Service,
|
T::Service,
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
>,
|
>,
|
||||||
F: IntoTransform<M, T::Service>,
|
F: IntoTransform<M, T::Service, ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
let endpoint = ApplyTransform::new(mw, self.endpoint);
|
let endpoint = ApplyTransform::new(mw, self.endpoint);
|
||||||
Resource {
|
Resource {
|
||||||
@ -216,12 +216,9 @@ where
|
|||||||
pub fn default_resource<F, R, U>(mut self, f: F) -> Self
|
pub fn default_resource<F, R, U>(mut self, f: F) -> Self
|
||||||
where
|
where
|
||||||
F: FnOnce(Resource<P>) -> R,
|
F: FnOnce(Resource<P>) -> R,
|
||||||
R: IntoNewService<U>,
|
R: IntoNewService<U, ServiceRequest<P>>,
|
||||||
U: NewService<
|
U: NewService<ServiceRequest<P>, Response = ServiceResponse, Error = ()>
|
||||||
Request = ServiceRequest<P>,
|
+ 'static,
|
||||||
Response = ServiceResponse,
|
|
||||||
Error = (),
|
|
||||||
> + 'static,
|
|
||||||
{
|
{
|
||||||
// create and configure default resource
|
// create and configure default resource
|
||||||
self.default = Rc::new(RefCell::new(Some(Rc::new(boxed::new_service(
|
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
|
where
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -260,8 +257,7 @@ pub struct ResourceFactory<P> {
|
|||||||
default: Rc<RefCell<Option<Rc<HttpNewService<P>>>>>,
|
default: Rc<RefCell<Option<Rc<HttpNewService<P>>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: 'static> NewService for ResourceFactory<P> {
|
impl<P: 'static> NewService<ServiceRequest<P>> for ResourceFactory<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -351,8 +347,7 @@ pub struct ResourceService<P> {
|
|||||||
default: Option<HttpService<P>>,
|
default: Option<HttpService<P>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> Service for ResourceService<P> {
|
impl<P> Service<ServiceRequest<P>> for ResourceService<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
@ -396,8 +391,7 @@ impl<P> ResourceEndpoint<P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: 'static> NewService for ResourceEndpoint<P> {
|
impl<P: 'static> NewService<ServiceRequest<P>> for ResourceEndpoint<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
|
47
src/route.rs
47
src/route.rs
@ -1,4 +1,5 @@
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
use std::marker::PhantomData;
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
|
|
||||||
use actix_http::{http::Method, Error, Extensions, Response};
|
use actix_http::{http::Method, Error, Extensions, Response};
|
||||||
@ -14,7 +15,7 @@ use crate::HttpResponse;
|
|||||||
|
|
||||||
type BoxedRouteService<Req, Res> = Box<
|
type BoxedRouteService<Req, Res> = Box<
|
||||||
Service<
|
Service<
|
||||||
Request = Req,
|
Req,
|
||||||
Response = Res,
|
Response = Res,
|
||||||
Error = (),
|
Error = (),
|
||||||
Future = Box<Future<Item = Res, Error = ()>>,
|
Future = Box<Future<Item = Res, Error = ()>>,
|
||||||
@ -23,7 +24,7 @@ type BoxedRouteService<Req, Res> = Box<
|
|||||||
|
|
||||||
type BoxedRouteNewService<Req, Res> = Box<
|
type BoxedRouteNewService<Req, Res> = Box<
|
||||||
NewService<
|
NewService<
|
||||||
Request = Req,
|
Req,
|
||||||
Response = Res,
|
Response = Res,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -85,8 +86,7 @@ impl<P: 'static> Route<P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> NewService for Route<P> {
|
impl<P> NewService<ServiceRequest<P>> for Route<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -141,8 +141,7 @@ impl<P> RouteService<P> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> Service for RouteService<P> {
|
impl<P> Service<ServiceRequest<P>> for RouteService<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::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()
|
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)
|
self.service.call(req)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -348,43 +347,46 @@ impl<P: 'static> Route<P> {
|
|||||||
|
|
||||||
struct RouteNewService<P, T>
|
struct RouteNewService<P, T>
|
||||||
where
|
where
|
||||||
T: NewService<Request = ServiceRequest<P>, Error = (Error, ServiceFromRequest<P>)>,
|
T: NewService<ServiceRequest<P>, Error = (Error, ServiceFromRequest<P>)>,
|
||||||
{
|
{
|
||||||
service: T,
|
service: T,
|
||||||
|
_t: PhantomData<P>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: 'static, T> RouteNewService<P, T>
|
impl<P: 'static, T> RouteNewService<P, T>
|
||||||
where
|
where
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (Error, ServiceFromRequest<P>),
|
Error = (Error, ServiceFromRequest<P>),
|
||||||
>,
|
>,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
T::Service: 'static,
|
T::Service: 'static,
|
||||||
<T::Service as Service>::Future: 'static,
|
<T::Service as Service<ServiceRequest<P>>>::Future: 'static,
|
||||||
{
|
{
|
||||||
pub fn new(service: T) -> Self {
|
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
|
where
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (Error, ServiceFromRequest<P>),
|
Error = (Error, ServiceFromRequest<P>),
|
||||||
>,
|
>,
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
T::Service: '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 Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
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>>;
|
type Future = Box<Future<Item = Self::Service, Error = Self::InitError>>;
|
||||||
|
|
||||||
fn new_service(&self, _: &()) -> Self::Future {
|
fn new_service(&self, _: &()) -> Self::Future {
|
||||||
@ -394,27 +396,30 @@ where
|
|||||||
.map_err(|_| ())
|
.map_err(|_| ())
|
||||||
.and_then(|service| {
|
.and_then(|service| {
|
||||||
let service: BoxedRouteService<_, _> =
|
let service: BoxedRouteService<_, _> =
|
||||||
Box::new(RouteServiceWrapper { service });
|
Box::new(RouteServiceWrapper {
|
||||||
|
service,
|
||||||
|
_t: PhantomData,
|
||||||
|
});
|
||||||
Ok(service)
|
Ok(service)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RouteServiceWrapper<P, T: Service<Request = ServiceRequest<P>>> {
|
struct RouteServiceWrapper<P, T: Service<ServiceRequest<P>>> {
|
||||||
service: T,
|
service: T,
|
||||||
|
_t: PhantomData<P>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P, T> Service for RouteServiceWrapper<P, T>
|
impl<P, T> Service<ServiceRequest<P>> for RouteServiceWrapper<P, T>
|
||||||
where
|
where
|
||||||
T::Future: 'static,
|
T::Future: 'static,
|
||||||
T: Service<
|
T: Service<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (Error, ServiceFromRequest<P>),
|
Error = (Error, ServiceFromRequest<P>),
|
||||||
>,
|
>,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
25
src/scope.rs
25
src/scope.rs
@ -79,7 +79,7 @@ impl<P: 'static> Scope<P> {
|
|||||||
impl<P: 'static, T> Scope<P, T>
|
impl<P: 'static, T> Scope<P, T>
|
||||||
where
|
where
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -196,7 +196,7 @@ where
|
|||||||
where
|
where
|
||||||
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
||||||
U: NewService<
|
U: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -219,7 +219,7 @@ where
|
|||||||
where
|
where
|
||||||
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
F: FnOnce(Resource<P>) -> Resource<P, U>,
|
||||||
U: NewService<
|
U: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -244,7 +244,7 @@ where
|
|||||||
) -> Scope<
|
) -> Scope<
|
||||||
P,
|
P,
|
||||||
impl NewService<
|
impl NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -253,12 +253,12 @@ where
|
|||||||
where
|
where
|
||||||
M: Transform<
|
M: Transform<
|
||||||
T::Service,
|
T::Service,
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
>,
|
>,
|
||||||
F: IntoTransform<M, T::Service>,
|
F: IntoTransform<M, T::Service, ServiceRequest<P>>,
|
||||||
{
|
{
|
||||||
let endpoint = ApplyTransform::new(mw, self.endpoint);
|
let endpoint = ApplyTransform::new(mw, self.endpoint);
|
||||||
Scope {
|
Scope {
|
||||||
@ -293,10 +293,10 @@ pub(crate) fn insert_slash(path: &str) -> String {
|
|||||||
path
|
path
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P, T> IntoNewService<T> for Scope<P, T>
|
impl<P, T> IntoNewService<T, ServiceRequest<P>> for Scope<P, T>
|
||||||
where
|
where
|
||||||
T: NewService<
|
T: NewService<
|
||||||
Request = ServiceRequest<P>,
|
ServiceRequest<P>,
|
||||||
Response = ServiceResponse,
|
Response = ServiceResponse,
|
||||||
Error = (),
|
Error = (),
|
||||||
InitError = (),
|
InitError = (),
|
||||||
@ -331,8 +331,7 @@ pub struct ScopeFactory<P> {
|
|||||||
default: Rc<RefCell<Option<Rc<HttpNewService<P>>>>>,
|
default: Rc<RefCell<Option<Rc<HttpNewService<P>>>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P: 'static> NewService for ScopeFactory<P> {
|
impl<P: 'static> NewService<ServiceRequest<P>> for ScopeFactory<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
@ -448,8 +447,7 @@ pub struct ScopeService<P> {
|
|||||||
_ready: Option<(ServiceRequest<P>, ResourceInfo)>,
|
_ready: Option<(ServiceRequest<P>, ResourceInfo)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<P> Service for ScopeService<P> {
|
impl<P> Service<ServiceRequest<P>> for ScopeService<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type Future = Either<BoxedResponse, FutureResult<Self::Response, Self::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> {
|
impl<P: 'static> NewService<ServiceRequest<P>> for ScopeEndpoint<P> {
|
||||||
type Request = ServiceRequest<P>;
|
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = ();
|
type Error = ();
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
|
@ -52,8 +52,8 @@ struct Config {
|
|||||||
pub struct HttpServer<F, I, S, B>
|
pub struct HttpServer<F, I, S, B>
|
||||||
where
|
where
|
||||||
F: Fn() -> I + Send + Clone + 'static,
|
F: Fn() -> I + Send + Clone + 'static,
|
||||||
I: IntoNewService<S>,
|
I: IntoNewService<S, Request>,
|
||||||
S: NewService<Request = Request>,
|
S: NewService<Request>,
|
||||||
S::Error: fmt::Debug,
|
S::Error: fmt::Debug,
|
||||||
S::Response: Into<Response<B>>,
|
S::Response: Into<Response<B>>,
|
||||||
S::Service: 'static,
|
S::Service: 'static,
|
||||||
@ -71,8 +71,8 @@ where
|
|||||||
impl<F, I, S, B> HttpServer<F, I, S, B>
|
impl<F, I, S, B> HttpServer<F, I, S, B>
|
||||||
where
|
where
|
||||||
F: Fn() -> I + Send + Clone + 'static,
|
F: Fn() -> I + Send + Clone + 'static,
|
||||||
I: IntoNewService<S>,
|
I: IntoNewService<S, Request>,
|
||||||
S: NewService<Request = Request>,
|
S: NewService<Request>,
|
||||||
S::Error: fmt::Debug,
|
S::Error: fmt::Debug,
|
||||||
S::Response: Into<Response<B>>,
|
S::Response: Into<Response<B>>,
|
||||||
S::Service: 'static,
|
S::Service: 'static,
|
||||||
@ -431,8 +431,8 @@ where
|
|||||||
impl<F, I, S, B> HttpServer<F, I, S, B>
|
impl<F, I, S, B> HttpServer<F, I, S, B>
|
||||||
where
|
where
|
||||||
F: Fn() -> I + Send + Clone + 'static,
|
F: Fn() -> I + Send + Clone + 'static,
|
||||||
I: IntoNewService<S>,
|
I: IntoNewService<S, Request>,
|
||||||
S: NewService<Request = Request>,
|
S: NewService<Request>,
|
||||||
S::Error: fmt::Debug,
|
S::Error: fmt::Debug,
|
||||||
S::Response: Into<Response<B>>,
|
S::Response: Into<Response<B>>,
|
||||||
S::Service: 'static,
|
S::Service: 'static,
|
||||||
|
@ -5,15 +5,15 @@ use std::rc::Rc;
|
|||||||
use actix_http::body::{Body, MessageBody, ResponseBody};
|
use actix_http::body::{Body, MessageBody, ResponseBody};
|
||||||
use actix_http::http::{HeaderMap, Method, Uri, Version};
|
use actix_http::http::{HeaderMap, Method, Uri, Version};
|
||||||
use actix_http::{
|
use actix_http::{
|
||||||
Error, Extensions, HttpMessage, Payload, Request, RequestHead, Response,
|
Error, Extensions, HttpMessage, Payload, PayloadStream, Request, RequestHead,
|
||||||
ResponseHead,
|
Response, ResponseHead,
|
||||||
};
|
};
|
||||||
use actix_router::{Path, Resource, Url};
|
use actix_router::{Path, Resource, Url};
|
||||||
use futures::future::{ok, FutureResult, IntoFuture};
|
use futures::future::{ok, FutureResult, IntoFuture};
|
||||||
|
|
||||||
use crate::request::HttpRequest;
|
use crate::request::HttpRequest;
|
||||||
|
|
||||||
pub struct ServiceRequest<P> {
|
pub struct ServiceRequest<P = PayloadStream> {
|
||||||
req: HttpRequest,
|
req: HttpRequest,
|
||||||
payload: Payload<P>,
|
payload: Payload<P>,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user