mirror of https://github.com/fafhrd91/actix-web
dedupe boxed http service aliases
This commit is contained in:
parent
21e3e1d620
commit
19096b9b36
|
@ -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,
|
||||
|
|
|
@ -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<Box<dyn Guard>>;
|
||||
type HttpService = BoxService<ServiceRequest, ServiceResponse, Error>;
|
||||
type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||
|
||||
/// Service factory to convert `Request` to a `ServiceRequest<S>`.
|
||||
/// It also executes data factories.
|
||||
|
@ -39,7 +36,7 @@ where
|
|||
pub(crate) extensions: RefCell<Option<Extensions>>,
|
||||
pub(crate) async_data_factories: Rc<[FnDataFactory]>,
|
||||
pub(crate) services: Rc<RefCell<Vec<Box<dyn AppServiceFactory>>>>,
|
||||
pub(crate) default: Option<Rc<HttpNewService>>,
|
||||
pub(crate) default: Option<Rc<HttpServiceFactory>>,
|
||||
pub(crate) factory_ref: Rc<RefCell<Option<AppRoutingFactory>>>,
|
||||
pub(crate) external: RefCell<Vec<ResourceDef>>,
|
||||
}
|
||||
|
@ -230,8 +227,8 @@ where
|
|||
}
|
||||
|
||||
pub struct AppRoutingFactory {
|
||||
services: Rc<[(ResourceDef, HttpNewService, RefCell<Option<Guards>>)]>,
|
||||
default: Rc<HttpNewService>,
|
||||
services: Rc<[(ResourceDef, HttpServiceFactory, RefCell<Option<Guards>>)]>,
|
||||
default: Rc<HttpServiceFactory>,
|
||||
}
|
||||
|
||||
impl ServiceFactory<ServiceRequest> for AppRoutingFactory {
|
||||
|
|
|
@ -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<ServiceRequest, ServiceResponse, Error>;
|
||||
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<T = ResourceEndpoint> {
|
|||
routes: Vec<Route>,
|
||||
app_data: Option<Extensions>,
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
default: HttpNewService,
|
||||
default: HttpServiceFactory,
|
||||
factory_ref: Rc<RefCell<Option<ResourceFactory>>>,
|
||||
}
|
||||
|
||||
|
@ -422,7 +418,7 @@ where
|
|||
|
||||
pub struct ResourceFactory {
|
||||
routes: Vec<Route>,
|
||||
default: HttpNewService,
|
||||
default: HttpServiceFactory,
|
||||
}
|
||||
|
||||
impl ServiceFactory<ServiceRequest> for ResourceFactory {
|
||||
|
|
18
src/scope.rs
18
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<Box<dyn Guard>>;
|
||||
type HttpService = BoxService<ServiceRequest, ServiceResponse, Error>;
|
||||
type HttpNewService = BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||
|
||||
/// Resources scope.
|
||||
///
|
||||
|
@ -58,7 +58,7 @@ pub struct Scope<T = ScopeEndpoint> {
|
|||
app_data: Option<Extensions>,
|
||||
services: Vec<Box<dyn AppServiceFactory>>,
|
||||
guards: Vec<Box<dyn Guard>>,
|
||||
default: Option<Rc<HttpNewService>>,
|
||||
default: Option<Rc<HttpServiceFactory>>,
|
||||
external: Vec<ResourceDef>,
|
||||
factory_ref: Rc<RefCell<Option<ScopeFactory>>>,
|
||||
}
|
||||
|
@ -470,8 +470,8 @@ where
|
|||
}
|
||||
|
||||
pub struct ScopeFactory {
|
||||
services: Rc<[(ResourceDef, HttpNewService, RefCell<Option<Guards>>)]>,
|
||||
default: Rc<HttpNewService>,
|
||||
services: Rc<[(ResourceDef, HttpServiceFactory, RefCell<Option<Guards>>)]>,
|
||||
default: Rc<HttpServiceFactory>,
|
||||
}
|
||||
|
||||
impl ServiceFactory<ServiceRequest> for ScopeFactory {
|
||||
|
|
|
@ -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<ServiceRequest, ServiceResponse, Error>;
|
||||
pub(crate) type HttpServiceFactory =
|
||||
BoxServiceFactory<(), ServiceRequest, ServiceResponse, Error, ()>;
|
||||
|
||||
pub trait HttpServiceFactory {
|
||||
fn register(self, config: &mut AppService);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue