1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2025-04-25 02:54:06 +00:00

Merge branch 'master' into issue1118

This commit is contained in:
SuperHacker-liuan 2019-10-07 11:43:58 +08:00 committed by GitHub
commit d078845cbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,16 +1,16 @@
//! Route match guards. //! Route match guards.
//! //!
//! Guards are one of the way how actix-web router chooses //! Guards are one of the ways how actix-web router chooses a
//! handler service. In essence it just function that accepts //! handler service. In essence it is just a function that accepts a
//! reference to a `RequestHead` instance and returns boolean. //! reference to a `RequestHead` instance and returns a boolean.
//! It is possible to add guards to *scopes*, *resources* //! It is possible to add guards to *scopes*, *resources*
//! and *routes*. Actix provide several guards by default, like various //! and *routes*. Actix provide several guards by default, like various
//! http methods, header, etc. To become a guard, type must implement `Guard` //! http methods, header, etc. To become a guard, type must implement `Guard`
//! trait. Simple functions coulds guards as well. //! trait. Simple functions coulds guards as well.
//! //!
//! Guard can not modify request object. But it is possible to //! Guards can not modify the request object. But it is possible
//! to store extra attributes on a request by using `Extensions` container. //! to store extra attributes on a request by using the `Extensions` container.
//! Extensions container available via `RequestHead::extensions()` method. //! Extensions containers are available via the `RequestHead::extensions()` method.
//! //!
//! ```rust //! ```rust
//! use actix_web::{web, http, dev, guard, App, HttpResponse}; //! use actix_web::{web, http, dev, guard, App, HttpResponse};
@ -29,11 +29,11 @@
use actix_http::http::{self, header, uri::Uri, HttpTryFrom}; use actix_http::http::{self, header, uri::Uri, HttpTryFrom};
use actix_http::RequestHead; use actix_http::RequestHead;
/// Trait defines resource guards. Guards are used for routes selection. /// Trait defines resource guards. Guards are used for route selection.
/// ///
/// Guard can not modify request object. But it is possible to /// Guards can not modify the request object. But it is possible
/// to store extra attributes on request by using `Extensions` container, /// to store extra attributes on a request by using the `Extensions` container.
/// Extensions container available via `RequestHead::extensions()` method. /// Extensions containers are available via the `RequestHead::extensions()` method.
pub trait Guard { pub trait Guard {
/// Check if request matches predicate /// Check if request matches predicate
fn check(&self, request: &RequestHead) -> bool; fn check(&self, request: &RequestHead) -> bool;