diff --git a/actix-http/src/body/mod.rs b/actix-http/src/body/mod.rs index b0a31609c..a863aa0a1 100644 --- a/actix-http/src/body/mod.rs +++ b/actix-http/src/body/mod.rs @@ -30,9 +30,9 @@ mod tests { use actix_utils::future::poll_fn; use bytes::{Bytes, BytesMut}; - use super::{to_bytes, AnyBody as TestAnyBody, BodySize, MessageBody as _}; + use super::{AnyBody as TestAnyBody, *}; - impl AnyBody { + impl TestAnyBody { pub(crate) fn get_ref(&self) -> &[u8] { match *self { AnyBody::Bytes(ref bin) => bin, diff --git a/src/app_service.rs b/src/app_service.rs index cf34b302e..6f9150379 100644 --- a/src/app_service.rs +++ b/src/app_service.rs @@ -2,10 +2,7 @@ use std::{cell::RefCell, mem, rc::Rc}; use actix_http::{Extensions, Request}; use actix_router::{Path, ResourceDef, Router, Url}; -use actix_service::{ - boxed::{self, BoxService, BoxServiceFactory}, - fn_service, Service, ServiceFactory, -}; +use actix_service::{boxed, fn_service, Service, ServiceFactory}; use futures_core::future::LocalBoxFuture; use futures_util::future::join_all; @@ -15,13 +12,13 @@ use crate::{ guard::Guard, request::{HttpRequest, HttpRequestPool}, rmap::ResourceMap, - service::{AppServiceFactory, ServiceRequest, ServiceResponse}, + service::{ + AppServiceFactory, HttpService, HttpServiceFactory, ServiceRequest, ServiceResponse, + }, Error, HttpResponse, }; type Guards = Vec>; -type HttpService = BoxService; -type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>; /// Service factory to convert `Request` to a `ServiceRequest`. /// It also executes data factories. @@ -39,7 +36,7 @@ where pub(crate) extensions: RefCell>, pub(crate) async_data_factories: Rc<[FnDataFactory]>, pub(crate) services: Rc>>>, - pub(crate) default: Option>, + pub(crate) default: Option>, pub(crate) factory_ref: Rc>>, pub(crate) external: RefCell>, } @@ -230,8 +227,8 @@ where } pub struct AppRoutingFactory { - services: Rc<[(ResourceDef, HttpNewService, RefCell>)]>, - default: Rc, + services: Rc<[(ResourceDef, HttpServiceFactory, RefCell>)]>, + default: Rc, } impl ServiceFactory for AppRoutingFactory { diff --git a/src/resource.rs b/src/resource.rs index 851ce0fc9..f59a1a01a 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -5,9 +5,8 @@ use std::rc::Rc; use actix_http::Extensions; use actix_router::{IntoPatterns, Patterns}; -use actix_service::boxed::{self, BoxService, BoxServiceFactory}; use actix_service::{ - apply, apply_fn_factory, fn_service, IntoServiceFactory, Service, ServiceFactory, + apply, apply_fn_factory, boxed, fn_service, IntoServiceFactory, Service, ServiceFactory, ServiceFactoryExt, Transform, }; use futures_core::future::LocalBoxFuture; @@ -20,13 +19,10 @@ use crate::{ handler::Handler, responder::Responder, route::{Route, RouteService}, - service::{ServiceRequest, ServiceResponse}, + service::{HttpService, HttpServiceFactory, ServiceRequest, ServiceResponse}, Error, FromRequest, HttpResponse, }; -type HttpService = BoxService; -type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>; - /// *Resource* is an entry in resources table which corresponds to requested URL. /// /// Resource in turn has at least one route. @@ -56,7 +52,7 @@ pub struct Resource { routes: Vec, app_data: Option, guards: Vec>, - default: HttpNewService, + default: HttpServiceFactory, factory_ref: Rc>>, } @@ -422,7 +418,7 @@ where pub struct ResourceFactory { routes: Vec, - default: HttpNewService, + default: HttpServiceFactory, } impl ServiceFactory for ResourceFactory { diff --git a/src/scope.rs b/src/scope.rs index c20b5d7c8..352e48cf6 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -3,9 +3,8 @@ use std::{cell::RefCell, fmt, future::Future, mem, rc::Rc}; use actix_http::Extensions; use actix_router::{ResourceDef, Router}; use actix_service::{ - apply, apply_fn_factory, - boxed::{self, BoxService, BoxServiceFactory}, - IntoServiceFactory, Service, ServiceFactory, ServiceFactoryExt, Transform, + apply, apply_fn_factory, boxed, IntoServiceFactory, Service, ServiceFactory, + ServiceFactoryExt, Transform, }; use futures_core::future::LocalBoxFuture; use futures_util::future::join_all; @@ -16,13 +15,14 @@ use crate::{ dev::{AppService, HttpServiceFactory}, guard::Guard, rmap::ResourceMap, - service::{AppServiceFactory, ServiceFactoryWrapper, ServiceRequest, ServiceResponse}, + service::{ + AppServiceFactory, HttpService, HttpServiceFactory, ServiceFactoryWrapper, + ServiceRequest, ServiceResponse, + }, Error, Resource, Route, }; type Guards = Vec>; -type HttpService = BoxService; -type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>; /// Resources scope. /// @@ -58,7 +58,7 @@ pub struct Scope { app_data: Option, services: Vec>, guards: Vec>, - default: Option>, + default: Option>, external: Vec, factory_ref: Rc>>, } @@ -470,8 +470,8 @@ where } pub struct ScopeFactory { - services: Rc<[(ResourceDef, HttpNewService, RefCell>)]>, - default: Rc, + services: Rc<[(ResourceDef, HttpServiceFactory, RefCell>)]>, + default: Rc, } impl ServiceFactory for ScopeFactory { diff --git a/src/service.rs b/src/service.rs index 8ba38df43..c60f8e1fc 100644 --- a/src/service.rs +++ b/src/service.rs @@ -3,12 +3,15 @@ use std::rc::Rc; use std::{fmt, net}; use actix_http::{ - body::{AnyBody, MessageBody}, + body::{AnyBody, BoxBody, MessageBody}, http::{HeaderMap, Method, StatusCode, Uri, Version}, Extensions, HttpMessage, Payload, PayloadStream, RequestHead, Response, ResponseHead, }; use actix_router::{IntoPatterns, Path, Patterns, Resource, ResourceDef, Url}; -use actix_service::{IntoServiceFactory, ServiceFactory}; +use actix_service::{ + boxed::{BoxService, BoxServiceFactory}, + IntoServiceFactory, ServiceFactory, +}; #[cfg(feature = "cookies")] use cookie::{Cookie, ParseError as CookieParseError}; @@ -21,6 +24,10 @@ use crate::{ Error, HttpRequest, HttpResponse, }; +pub(crate) type HttpService = BoxService; +pub(crate) type HttpServiceFactory = + BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>; + pub trait HttpServiceFactory { fn register(self, config: &mut AppService); }