1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-27 17:22:57 +01:00

use Error explicitly

This commit is contained in:
Nikolay Kim 2019-04-25 11:14:32 -07:00
parent cba78e06ae
commit 70a4c36496
8 changed files with 43 additions and 44 deletions

View File

@ -6,7 +6,7 @@ use std::str::FromStr;
use actix_http::body::MessageBody;
use actix_http::encoding::Encoder;
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 futures::future::{ok, FutureResult};
use futures::{Async, Future, Poll};
@ -71,11 +71,11 @@ impl Default for Compress {
impl<S, B> Transform<S> for Compress
where
B: MessageBody,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
{
type Request = ServiceRequest;
type Response = ServiceResponse<Encoder<B>>;
type Error = S::Error;
type Error = Error;
type InitError = ();
type Transform = CompressMiddleware<S>;
type Future = FutureResult<Self::Transform, Self::InitError>;
@ -96,11 +96,11 @@ pub struct CompressMiddleware<S> {
impl<S, B> Service for CompressMiddleware<S>
where
B: MessageBody,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
{
type Request = ServiceRequest;
type Response = ServiceResponse<Encoder<B>>;
type Error = S::Error;
type Error = Error;
type Future = CompressResponse<S, B>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
@ -141,10 +141,10 @@ where
impl<S, B> Future for CompressResponse<S, B>
where
B: MessageBody,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
{
type Item = ServiceResponse<Encoder<B>>;
type Error = S::Error;
type Error = Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
let resp = futures::try_ready!(self.fut.poll());

View File

@ -47,7 +47,7 @@ use futures::future::{ok, Either, Future, FutureResult};
use futures::Poll;
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::{self, HttpTryFrom, Method, StatusCode, Uri};
use crate::service::{ServiceRequest, ServiceResponse};
@ -477,9 +477,8 @@ fn cors<'a>(
impl<S, B> IntoTransform<CorsFactory, S> for Cors
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
S::Error: 'static,
B: 'static,
{
fn into_transform(self) -> CorsFactory {
@ -539,14 +538,13 @@ pub struct CorsFactory {
impl<S, B> Transform<S> for CorsFactory
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
S::Error: 'static,
B: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = S::Error;
type Error = Error;
type InitError = ();
type Transform = CorsMiddleware<S>;
type Future = FutureResult<Self::Transform, Self::InitError>;
@ -680,17 +678,16 @@ impl Inner {
impl<S, B> Service for CorsMiddleware<S>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
S::Error: 'static,
B: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = S::Error;
type Error = Error;
type Future = Either<
FutureResult<Self::Response, Self::Error>,
Either<S::Future, Box<Future<Item = Self::Response, Error = Self::Error>>>,
FutureResult<Self::Response, Error>,
Either<S::Future, Box<Future<Item = Self::Response, Error = Error>>>,
>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
@ -820,10 +817,12 @@ mod tests {
impl Cors {
fn finish<S, B>(self, srv: S) -> CorsMiddleware<S>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>
+ 'static,
S: Service<
Request = ServiceRequest,
Response = ServiceResponse<B>,
Error = Error,
> + 'static,
S::Future: 'static,
S::Error: 'static,
B: 'static,
{
block_on(

View File

@ -8,6 +8,7 @@ use futures::{Future, Poll};
use crate::http::header::{HeaderName, HeaderValue, CONTENT_TYPE};
use crate::http::{HeaderMap, HttpTryFrom};
use crate::service::{ServiceRequest, ServiceResponse};
use crate::Error;
/// `Middleware` for setting default response headers.
///
@ -87,12 +88,12 @@ impl DefaultHeaders {
impl<S, B> Transform<S> for DefaultHeaders
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = S::Error;
type Error = Error;
type InitError = ();
type Transform = DefaultHeadersMiddleware<S>;
type Future = FutureResult<Self::Transform, Self::InitError>;
@ -112,12 +113,12 @@ pub struct DefaultHeadersMiddleware<S> {
impl<S, B> Service for DefaultHeadersMiddleware<S>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = S::Error;
type Error = Error;
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {

View File

@ -85,7 +85,6 @@ impl<S, B> Transform<S> for ErrorHandlers<B>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
S::Error: 'static,
B: 'static,
{
type Request = ServiceRequest;
@ -113,7 +112,6 @@ impl<S, B> Service for ErrorHandlersMiddleware<S, B>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
S::Future: 'static,
S::Error: 'static,
B: 'static,
{
type Request = ServiceRequest;

View File

@ -203,15 +203,15 @@ impl<T> IdentityService<T> {
impl<S, T, B> Transform<S> for IdentityService<T>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>> + 'static,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>
+ 'static,
S::Future: 'static,
S::Error: 'static,
T: IdentityPolicy,
B: 'static,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = S::Error;
type Error = Error;
type InitError = ();
type Transform = IdentityServiceMiddleware<S, T>;
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>
where
B: 'static,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>> + 'static,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>
+ 'static,
S::Future: 'static,
S::Error: 'static,
T: IdentityPolicy,
{
type Request = ServiceRequest;
type Response = ServiceResponse<B>;
type Error = S::Error;
type Error = Error;
type Future = Box<Future<Item = Self::Response, Error = Self::Error>>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {

View File

@ -116,12 +116,12 @@ impl Default for Logger {
impl<S, B> Transform<S> for Logger
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody,
{
type Request = ServiceRequest;
type Response = ServiceResponse<StreamLog<B>>;
type Error = S::Error;
type Error = Error;
type InitError = ();
type Transform = LoggerMiddleware<S>;
type Future = FutureResult<Self::Transform, Self::InitError>;
@ -142,12 +142,12 @@ pub struct LoggerMiddleware<S> {
impl<S, B> Service for LoggerMiddleware<S>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
B: MessageBody,
{
type Request = ServiceRequest;
type Response = ServiceResponse<StreamLog<B>>;
type Error = S::Error;
type Error = Error;
type Future = LoggerResponse<S, B>;
fn poll_ready(&mut self) -> Poll<(), Self::Error> {
@ -194,10 +194,10 @@ where
impl<S, B> Future for LoggerResponse<S, B>
where
B: MessageBody,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>>,
S: Service<Request = ServiceRequest, Response = ServiceResponse<B>, Error = Error>,
{
type Item = ServiceResponse<StreamLog<B>>;
type Error = S::Error;
type Error = Error;
fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
let res = futures::try_ready!(self.fut.poll());

View File

@ -5,6 +5,7 @@ use futures::future::{self, FutureResult};
use regex::Regex;
use crate::service::{ServiceRequest, ServiceResponse};
use crate::Error;
#[derive(Default, Clone, Copy)]
/// `Middleware` to normalize request's URI in place
@ -16,11 +17,11 @@ pub struct NormalizePath;
impl<S> Transform<S> for NormalizePath
where
S: Service<Request = ServiceRequest, Response = ServiceResponse>,
S: Service<Request = ServiceRequest, Response = ServiceResponse, Error = Error>,
{
type Request = ServiceRequest;
type Response = ServiceResponse;
type Error = S::Error;
type Error = Error;
type InitError = ();
type Transform = NormalizePathNormalization<S>;
type Future = FutureResult<Self::Transform, Self::InitError>;
@ -40,11 +41,11 @@ pub struct NormalizePathNormalization<S> {
impl<S> Service for NormalizePathNormalization<S>
where
S: Service<Request = ServiceRequest, Response = ServiceResponse>,
S: Service<Request = ServiceRequest, Response = ServiceResponse, Error = Error>,
{
type Request = ServiceRequest;
type Response = ServiceResponse;
type Error = S::Error;
type Error = Error;
type Future = S::Future;
fn poll_ready(&mut self) -> futures::Poll<(), Self::Error> {

View File

@ -247,7 +247,7 @@ where
/// Registers middleware, in the form of a closure, that runs during inbound
/// 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
/// to Route or Application level middleware, in that Scope-level middleware
/// can not modify ServiceResponse.