mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-27 15:29:03 +02:00
revert generic request parameter for service; support ServerConfig as new factory config
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
use std::io::Write;
|
||||
use std::marker::PhantomData;
|
||||
use std::str::FromStr;
|
||||
use std::{cmp, fmt, io};
|
||||
|
||||
@ -36,13 +37,14 @@ impl Default for Compress {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, P, B> Transform<S, ServiceRequest<P>> for Compress
|
||||
impl<S, P, B> Transform<S> for Compress
|
||||
where
|
||||
P: 'static,
|
||||
B: MessageBody,
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S::Future: 'static,
|
||||
{
|
||||
type Request = ServiceRequest<P>;
|
||||
type Response = ServiceResponse<Encoder<B>>;
|
||||
type Error = S::Error;
|
||||
type InitError = ();
|
||||
@ -62,13 +64,14 @@ pub struct CompressMiddleware<S> {
|
||||
encoding: ContentEncoding,
|
||||
}
|
||||
|
||||
impl<S, P, B> Service<ServiceRequest<P>> for CompressMiddleware<S>
|
||||
impl<S, P, B> Service for CompressMiddleware<S>
|
||||
where
|
||||
P: 'static,
|
||||
B: MessageBody,
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service<Request = 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>;
|
||||
@ -92,6 +95,7 @@ where
|
||||
CompressResponse {
|
||||
encoding,
|
||||
fut: self.service.call(req),
|
||||
_t: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,18 +105,19 @@ pub struct CompressResponse<S, P, B>
|
||||
where
|
||||
P: 'static,
|
||||
B: MessageBody,
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service,
|
||||
S::Future: 'static,
|
||||
{
|
||||
fut: S::Future,
|
||||
encoding: ContentEncoding,
|
||||
_t: PhantomData<(P, B)>,
|
||||
}
|
||||
|
||||
impl<S, P, B> Future for CompressResponse<S, P, B>
|
||||
where
|
||||
P: 'static,
|
||||
B: MessageBody,
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S::Future: 'static,
|
||||
{
|
||||
type Item = ServiceResponse<Encoder<B>>;
|
||||
|
@ -85,11 +85,12 @@ impl DefaultHeaders {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, P, B> Transform<S, ServiceRequest<P>> for DefaultHeaders
|
||||
impl<S, P, B> Transform<S> for DefaultHeaders
|
||||
where
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S::Future: 'static,
|
||||
{
|
||||
type Request = ServiceRequest<P>;
|
||||
type Response = ServiceResponse<B>;
|
||||
type Error = S::Error;
|
||||
type InitError = ();
|
||||
@ -109,11 +110,12 @@ pub struct DefaultHeadersMiddleware<S> {
|
||||
inner: Rc<Inner>,
|
||||
}
|
||||
|
||||
impl<S, P, B> Service<ServiceRequest<P>> for DefaultHeadersMiddleware<S>
|
||||
impl<S, P, B> Service for DefaultHeadersMiddleware<S>
|
||||
where
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service<Request = 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>>;
|
||||
|
@ -2,6 +2,7 @@
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::marker::PhantomData;
|
||||
use std::rc::Rc;
|
||||
|
||||
use actix_service::{Service, Transform};
|
||||
@ -110,11 +111,12 @@ impl Default for Logger {
|
||||
}
|
||||
}
|
||||
|
||||
impl<S, P, B> Transform<S, ServiceRequest<P>> for Logger
|
||||
impl<S, P, B> Transform<S> for Logger
|
||||
where
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
B: MessageBody,
|
||||
{
|
||||
type Request = ServiceRequest<P>;
|
||||
type Response = ServiceResponse<StreamLog<B>>;
|
||||
type Error = S::Error;
|
||||
type InitError = ();
|
||||
@ -135,11 +137,12 @@ pub struct LoggerMiddleware<S> {
|
||||
service: S,
|
||||
}
|
||||
|
||||
impl<S, P, B> Service<ServiceRequest<P>> for LoggerMiddleware<S>
|
||||
impl<S, P, B> Service for LoggerMiddleware<S>
|
||||
where
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
B: MessageBody,
|
||||
{
|
||||
type Request = ServiceRequest<P>;
|
||||
type Response = ServiceResponse<StreamLog<B>>;
|
||||
type Error = S::Error;
|
||||
type Future = LoggerResponse<S, P, B>;
|
||||
@ -154,6 +157,7 @@ where
|
||||
fut: self.service.call(req),
|
||||
format: None,
|
||||
time: time::now(),
|
||||
_t: PhantomData,
|
||||
}
|
||||
} else {
|
||||
let now = time::now();
|
||||
@ -166,6 +170,7 @@ where
|
||||
fut: self.service.call(req),
|
||||
format: Some(format),
|
||||
time: now,
|
||||
_t: PhantomData,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -175,17 +180,18 @@ where
|
||||
pub struct LoggerResponse<S, P, B>
|
||||
where
|
||||
B: MessageBody,
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service,
|
||||
{
|
||||
fut: S::Future,
|
||||
time: time::Tm,
|
||||
format: Option<Format>,
|
||||
_t: PhantomData<(P, B)>,
|
||||
}
|
||||
|
||||
impl<S, P, B> Future for LoggerResponse<S, P, B>
|
||||
where
|
||||
B: MessageBody,
|
||||
S: Service<ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
S: Service<Request = ServiceRequest<P>, Response = ServiceResponse<B>>,
|
||||
{
|
||||
type Item = ServiceResponse<StreamLog<B>>;
|
||||
type Error = S::Error;
|
||||
|
Reference in New Issue
Block a user