Module actix_web::guard[][src]

Expand description

Route match guards.

Guards are one of the ways how actix-web router chooses a handler service. In essence it is just a function that accepts a reference to a RequestHead instance and returns a 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 could be guards as well.

Guards can not modify the request object. But it is possible to store extra attributes on a request by using the Extensions container. Extensions containers are available via the 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(guard::fn_guard(|head| head.method == http::Method::GET))
             .to(|| HttpResponse::MethodNotAllowed()))
    );
}

Structs

Matches if all of supplied guards.

Matches any of supplied guards.

Traits

Trait defines resource guards. Guards are used for route selection.

Functions

Return guard that matches if all of the supplied guards.

Return guard that matches if any of supplied guards.

Predicate to match CONNECT HTTP method.

Predicate to match DELETE HTTP method.

Guard to match GET HTTP method.

Predicate to match HEAD HTTP method.

Return predicate that matches if request contains specified header and value.

Return predicate that matches if request contains specified Host name.

Predicate to match specified HTTP method.

Return guard that matches if supplied guard does not match.

Predicate to match OPTIONS HTTP method.

Predicate to match PATCH HTTP method.

Predicate to match POST HTTP method.

Predicate to match PUT HTTP method.

Predicate to match TRACE HTTP method.

Create guard object for supplied function.