[−][src]Module actix_web::guard
Route match guards.
Guards are one of the way how actix-web router chooses
handler service. In essence it just function that accepts
reference to a RequestHead
instance and returns boolean.
It is possible to add guards to scopes, resources
and routes. Actix provide several guards by default, like various
http methods, header, etc. To become a guard, type must implement Guard
trait. Simple functions coulds guards as well.
Guard can not modify request object. But it is possible to
to store extra attributes on a request by using Extensions
container.
Extensions container available via RequestHead::extensions()
method.
use actix_web::{web, http, dev, guard, App, HttpResponse}; fn main() { App::new().service(web::resource("/index.html").route( web::route() .guard(guard::Post()) .guard(|head: &dev::RequestHead| head.method == http::Method::GET) .to(|| HttpResponse::MethodNotAllowed())) ); }
Structs
AllGuard | Matches if all of supplied guards. |
AnyGuard | Matches if any of supplied guards matche. |
Traits
Guard | Trait defines resource guards. Guards are used for routes selection. |
Functions
All | Return guard that matches if all of the supplied guards. |
Any | Return guard that matches if any of supplied guards. |
Connect | Predicate to match CONNECT http method |
Delete | Predicate to match DELETE http method |
Get | Guard to match GET http method |
Head | Predicate to match HEAD http method |
Header | Return predicate that matches if request contains specified header and value. |
Method | Predicate to match specified http method |
Not | Return guard that matches if supplied guard does not match. |
Options | Predicate to match OPTIONS http method |
Patch | Predicate to match PATCH http method |
Post | Predicate to match POST http method |
Put | Predicate to match PUT http method |
Trace | Predicate to match TRACE http method |