mirror of
https://github.com/actix/actix-web.git
synced 2024-12-21 23:56:35 +00:00
use Error explicitly
This commit is contained in:
parent
cba78e06ae
commit
70a4c36496
8 changed files with 43 additions and 44 deletions
|
@ -6,7 +6,7 @@ use std::str::FromStr;
|
||||||
use actix_http::body::MessageBody;
|
use actix_http::body::MessageBody;
|
||||||
use actix_http::encoding::Encoder;
|
use actix_http::encoding::Encoder;
|
||||||
use actix_http::http::header::{ContentEncoding, ACCEPT_ENCODING};
|
use actix_http::http::header::{ContentEncoding, ACCEPT_ENCODING};
|
||||||
use actix_http::{Response, ResponseBuilder};
|
use actix_http::{Error, Response, ResponseBuilder};
|
||||||
use actix_service::{Service, Transform};
|
use actix_service::{Service, Transform};
|
||||||
use futures::future::{ok, FutureResult};
|
use futures::future::{ok, FutureResult};
|
||||||
use futures::{Async, Future, Poll};
|
use futures::{Async, Future, Poll};
|
||||||
|
@ -71,11 +71,11 @@ impl Default for Compress {
|
||||||
impl<S, B> Transform<S> for Compress
|
impl<S, B> Transform<S> for Compress
|
||||||
where
|
where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<Encoder<B>>;
|
type Response = ServiceResponse<Encoder<B>>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = CompressMiddleware<S>;
|
type Transform = CompressMiddleware<S>;
|
||||||
type Future = FutureResult<Self::Transform, Self::InitError>;
|
type Future = FutureResult<Self::Transform, Self::InitError>;
|
||||||
|
@ -96,11 +96,11 @@ pub struct CompressMiddleware<S> {
|
||||||
impl<S, B> Service for CompressMiddleware<S>
|
impl<S, B> Service for CompressMiddleware<S>
|
||||||
where
|
where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<Encoder<B>>;
|
type Response = ServiceResponse<Encoder<B>>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type Future = CompressResponse<S, B>;
|
type Future = CompressResponse<S, B>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
@ -141,10 +141,10 @@ where
|
||||||
impl<S, B> Future for CompressResponse<S, B>
|
impl<S, B> Future for CompressResponse<S, B>
|
||||||
where
|
where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
{
|
{
|
||||||
type Item = ServiceResponse<Encoder<B>>;
|
type Item = ServiceResponse<Encoder<B>>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
let resp = futures::try_ready!(self.fut.poll());
|
let resp = futures::try_ready!(self.fut.poll());
|
||||||
|
|
|
@ -47,7 +47,7 @@ use futures::future::{ok, Either, Future, FutureResult};
|
||||||
use futures::Poll;
|
use futures::Poll;
|
||||||
|
|
||||||
use crate::dev::RequestHead;
|
use crate::dev::RequestHead;
|
||||||
use crate::error::{ResponseError, Result};
|
use crate::error::{Error, ResponseError, Result};
|
||||||
use crate::http::header::{self, HeaderName, HeaderValue};
|
use crate::http::header::{self, HeaderName, HeaderValue};
|
||||||
use crate::http::{self, HttpTryFrom, Method, StatusCode, Uri};
|
use crate::http::{self, HttpTryFrom, Method, StatusCode, Uri};
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
|
@ -477,9 +477,8 @@ fn cors<'a>(
|
||||||
|
|
||||||
impl<S, B> IntoTransform<CorsFactory, S> for Cors
|
impl<S, B> IntoTransform<CorsFactory, S> for Cors
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
|
||||||
B: 'static,
|
B: 'static,
|
||||||
{
|
{
|
||||||
fn into_transform(self) -> CorsFactory {
|
fn into_transform(self) -> CorsFactory {
|
||||||
|
@ -539,14 +538,13 @@ pub struct CorsFactory {
|
||||||
|
|
||||||
impl<S, B> Transform<S> for CorsFactory
|
impl<S, B> Transform<S> for CorsFactory
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
|
||||||
B: 'static,
|
B: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = CorsMiddleware<S>;
|
type Transform = CorsMiddleware<S>;
|
||||||
type Future = FutureResult<Self::Transform, Self::InitError>;
|
type Future = FutureResult<Self::Transform, Self::InitError>;
|
||||||
|
@ -680,17 +678,16 @@ impl Inner {
|
||||||
|
|
||||||
impl<S, B> Service for CorsMiddleware<S>
|
impl<S, B> Service for CorsMiddleware<S>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
|
||||||
B: 'static,
|
B: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type Future = Either<
|
type Future = Either<
|
||||||
FutureResult<Self::Response, Self::Error>,
|
FutureResult<Self::Response, Error>,
|
||||||
Either<S::Future, Box<Future<Item = Self::Response, Error = Self::Error>>>,
|
Either<S::Future, Box<Future<Item = Self::Response, Error = Error>>>,
|
||||||
>;
|
>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
@ -820,10 +817,12 @@ mod tests {
|
||||||
impl Cors {
|
impl Cors {
|
||||||
fn finish<S, B>(self, srv: S) -> CorsMiddleware<S>
|
fn finish<S, B>(self, srv: S) -> CorsMiddleware<S>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>
|
S: Service<
|
||||||
+ 'static,
|
Request = ServiceRequest,
|
||||||
|
Response = ServiceResponse<B>,
|
||||||
|
Error = Error,
|
||||||
|
> + 'static,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
|
||||||
B: 'static,
|
B: 'static,
|
||||||
{
|
{
|
||||||
block_on(
|
block_on(
|
||||||
|
|
|
@ -8,6 +8,7 @@ use futures::{Future, Poll};
|
||||||
use crate::http::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
use crate::http::header::{HeaderName, HeaderValue, CONTENT_TYPE};
|
||||||
use crate::http::{HeaderMap, HttpTryFrom};
|
use crate::http::{HeaderMap, HttpTryFrom};
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
/// `Middleware` for setting default response headers.
|
/// `Middleware` for setting default response headers.
|
||||||
///
|
///
|
||||||
|
@ -87,12 +88,12 @@ impl DefaultHeaders {
|
||||||
|
|
||||||
impl<S, B> Transform<S> for DefaultHeaders
|
impl<S, B> Transform<S> for DefaultHeaders
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = DefaultHeadersMiddleware<S>;
|
type Transform = DefaultHeadersMiddleware<S>;
|
||||||
type Future = FutureResult<Self::Transform, Self::InitError>;
|
type Future = FutureResult<Self::Transform, Self::InitError>;
|
||||||
|
@ -112,12 +113,12 @@ pub struct DefaultHeadersMiddleware<S> {
|
||||||
|
|
||||||
impl<S, B> Service for DefaultHeadersMiddleware<S>
|
impl<S, B> Service for DefaultHeadersMiddleware<S>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
|
|
@ -85,7 +85,6 @@ impl<S, B> Transform<S> for ErrorHandlers<B>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
|
||||||
B: 'static,
|
B: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
|
@ -113,7 +112,6 @@ impl<S, B> Service for ErrorHandlersMiddleware<S, B>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
|
||||||
B: 'static,
|
B: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
|
|
|
@ -203,15 +203,15 @@ impl<T> IdentityService<T> {
|
||||||
|
|
||||||
impl<S, T, B> Transform<S> for IdentityService<T>
|
impl<S, T, B> Transform<S> for IdentityService<T>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>> + 'static,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>
|
||||||
|
+ 'static,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
|
||||||
T: IdentityPolicy,
|
T: IdentityPolicy,
|
||||||
B: 'static,
|
B: 'static,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = IdentityServiceMiddleware<S, T>;
|
type Transform = IdentityServiceMiddleware<S, T>;
|
||||||
type Future = FutureResult<Self::Transform, Self::InitError>;
|
type Future = FutureResult<Self::Transform, Self::InitError>;
|
||||||
|
@ -233,14 +233,14 @@ pub struct IdentityServiceMiddleware<S, T> {
|
||||||
impl<S, T, B> Service for IdentityServiceMiddleware<S, T>
|
impl<S, T, B> Service for IdentityServiceMiddleware<S, T>
|
||||||
where
|
where
|
||||||
B: 'static,
|
B: 'static,
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>> + 'static,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>
|
||||||
|
+ 'static,
|
||||||
S::Future: 'static,
|
S::Future: 'static,
|
||||||
S::Error: 'static,
|
|
||||||
T: IdentityPolicy,
|
T: IdentityPolicy,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<B>;
|
type Response = ServiceResponse<B>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
|
|
@ -116,12 +116,12 @@ impl Default for Logger {
|
||||||
|
|
||||||
impl<S, B> Transform<S> for Logger
|
impl<S, B> Transform<S> for Logger
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<StreamLog<B>>;
|
type Response = ServiceResponse<StreamLog<B>>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = LoggerMiddleware<S>;
|
type Transform = LoggerMiddleware<S>;
|
||||||
type Future = FutureResult<Self::Transform, Self::InitError>;
|
type Future = FutureResult<Self::Transform, Self::InitError>;
|
||||||
|
@ -142,12 +142,12 @@ pub struct LoggerMiddleware<S> {
|
||||||
|
|
||||||
impl<S, B> Service for LoggerMiddleware<S>
|
impl<S, B> Service for LoggerMiddleware<S>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse<StreamLog<B>>;
|
type Response = ServiceResponse<StreamLog<B>>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type Future = LoggerResponse<S, B>;
|
type Future = LoggerResponse<S, B>;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
|
||||||
|
@ -194,10 +194,10 @@ where
|
||||||
impl<S, B> Future for LoggerResponse<S, B>
|
impl<S, B> Future for LoggerResponse<S, B>
|
||||||
where
|
where
|
||||||
B: MessageBody,
|
B: MessageBody,
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
|
||||||
{
|
{
|
||||||
type Item = ServiceResponse<StreamLog<B>>;
|
type Item = ServiceResponse<StreamLog<B>>;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
|
||||||
let res = futures::try_ready!(self.fut.poll());
|
let res = futures::try_ready!(self.fut.poll());
|
||||||
|
|
|
@ -5,6 +5,7 @@ use futures::future::{self, FutureResult};
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::service::{ServiceRequest, ServiceResponse};
|
use crate::service::{ServiceRequest, ServiceResponse};
|
||||||
|
use crate::Error;
|
||||||
|
|
||||||
#[derive(Default, Clone, Copy)]
|
#[derive(Default, Clone, Copy)]
|
||||||
/// `Middleware` to normalize request's URI in place
|
/// `Middleware` to normalize request's URI in place
|
||||||
|
@ -16,11 +17,11 @@ pub struct NormalizePath;
|
||||||
|
|
||||||
impl<S> Transform<S> for NormalizePath
|
impl<S> Transform<S> for NormalizePath
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse, Error = Error>,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type InitError = ();
|
type InitError = ();
|
||||||
type Transform = NormalizePathNormalization<S>;
|
type Transform = NormalizePathNormalization<S>;
|
||||||
type Future = FutureResult<Self::Transform, Self::InitError>;
|
type Future = FutureResult<Self::Transform, Self::InitError>;
|
||||||
|
@ -40,11 +41,11 @@ pub struct NormalizePathNormalization<S> {
|
||||||
|
|
||||||
impl<S> Service for NormalizePathNormalization<S>
|
impl<S> Service for NormalizePathNormalization<S>
|
||||||
where
|
where
|
||||||
S: Service<Request = ServiceRequest, Response = ServiceResponse>,
|
S: Service<Request = ServiceRequest, Response = ServiceResponse, Error = Error>,
|
||||||
{
|
{
|
||||||
type Request = ServiceRequest;
|
type Request = ServiceRequest;
|
||||||
type Response = ServiceResponse;
|
type Response = ServiceResponse;
|
||||||
type Error = S::Error;
|
type Error = Error;
|
||||||
type Future = S::Future;
|
type Future = S::Future;
|
||||||
|
|
||||||
fn poll_ready(&mut self) -> futures::Poll<(), Self::Error> {
|
fn poll_ready(&mut self) -> futures::Poll<(), Self::Error> {
|
||||||
|
|
|
@ -247,7 +247,7 @@ where
|
||||||
|
|
||||||
/// Registers middleware, in the form of a closure, that runs during inbound
|
/// Registers middleware, in the form of a closure, that runs during inbound
|
||||||
/// processing in the request lifecycle (request -> response), modifying
|
/// processing in the request lifecycle (request -> response), modifying
|
||||||
/// request as necessary, across all requests managed by the *Scope*.
|
/// request as necessary, across all requests managed by the *Scope*.
|
||||||
/// Scope-level middleware is more limited in what it can modify, relative
|
/// Scope-level middleware is more limited in what it can modify, relative
|
||||||
/// to Route or Application level middleware, in that Scope-level middleware
|
/// to Route or Application level middleware, in that Scope-level middleware
|
||||||
/// can not modify ServiceResponse.
|
/// can not modify ServiceResponse.
|
||||||
|
|
Loading…
Reference in a new issue