pub struct Chain { /* private fields */ }Expand description
Actix-Web service chaining service.
The chain is constructed from a series of Link
instances which encode when services should be run and when
their responses should be reguarded in favor of running the next
service.
Chain service must be registered with App::service() method.
§Examples
use actix_web::{App, HttpRequest, HttpResponse, Responder, web};
use actix_chain::{Chain, Link};
async fn might_fail(req: HttpRequest) -> impl Responder {
if !req.headers().contains_key("Required-Header") {
return HttpResponse::NotFound().body("Request Failed");
}
HttpResponse::Ok().body("It worked!")
}
async fn default() -> &'static str {
"First link failed!"
}
App::new().service(
Chain::default()
.link(Link::new(web::get().to(might_fail)))
.link(Link::new(web::get().to(default)))
);Implementations§
Source§impl Chain
impl Chain
Sourcepub fn new(mount_path: &str) -> Self
pub fn new(mount_path: &str) -> Self
Creates new Chain instance.
The first argument (mount_path) is the root URL at which the static files are served.
For example, /assets will serve files at example.com/assets/....
Sourcepub fn guard<G: Guard + 'static>(self, guards: G) -> Self
pub fn guard<G: Guard + 'static>(self, guards: G) -> Self
Adds a routing guard.
Use this to allow multiple chained services that respond to strictly different properties of a request. Due to the way routing works, if a guard check returns true and the request starts being handled by the file service, it will not be able to back-out and try the next service, you will simply get a 404 (or 405) error response.
§Examples
use actix_web::{guard::Header, App};
use actix_chain::Chain;
App::new().service(
Chain::default()
.guard(Header("Host", "example.com"))
);Trait Implementations§
Source§impl HttpServiceFactory for Chain
impl HttpServiceFactory for Chain
fn register(self, config: &mut AppService)
Source§impl ServiceFactory<ServiceRequest> for Chain
impl ServiceFactory<ServiceRequest> for Chain
Source§type Response = ServiceResponse
type Response = ServiceResponse
Source§type Service = ChainService
type Service = ChainService
Service created by this factory.Source§type Future = Pin<Box<dyn Future<Output = Result<<Chain as ServiceFactory<ServiceRequest>>::Service, <Chain as ServiceFactory<ServiceRequest>>::InitError>>>>
type Future = Pin<Box<dyn Future<Output = Result<<Chain as ServiceFactory<ServiceRequest>>::Service, <Chain as ServiceFactory<ServiceRequest>>::InitError>>>>
Service instance.gSource§fn new_service(&self, _: ()) -> Self::Future
fn new_service(&self, _: ()) -> Self::Future
Auto Trait Implementations§
impl Freeze for Chain
impl !RefUnwindSafe for Chain
impl !Send for Chain
impl !Sync for Chain
impl Unpin for Chain
impl !UnwindSafe for Chain
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<SF, Req> IntoServiceFactory<SF, Req> for SFwhere
SF: ServiceFactory<Req>,
impl<SF, Req> IntoServiceFactory<SF, Req> for SFwhere
SF: ServiceFactory<Req>,
Source§fn into_factory(self) -> SF
fn into_factory(self) -> SF
Self to a ServiceFactory