mirror of
https://github.com/actix/actix-website
synced 2024-11-23 16:31:08 +01:00
Update virtual hosting example to use guard::Host instead of guard::Header (#318)
This commit is contained in:
parent
5fa564fd4e
commit
77920d65fe
@ -66,7 +66,7 @@ In the above example, the `show_users` route will have an effective route patter
|
|||||||
|
|
||||||
You can think of a guard as a simple function that accepts a _request_ object reference and returns _true_ or _false_. Formally, a guard is any object that implements the [`Guard`][guardtrait] trait. Actix Web provides several guards. You can check the [functions section][guardfuncs] of the API docs.
|
You can think of a guard as a simple function that accepts a _request_ object reference and returns _true_ or _false_. Formally, a guard is any object that implements the [`Guard`][guardtrait] trait. Actix Web provides several guards. You can check the [functions section][guardfuncs] of the API docs.
|
||||||
|
|
||||||
One of the provided guards is [`Header`][guardheader]. It can be used as a filter based on request header information.
|
One of the provided guards is [`Host`][guardheader]. It can be used as a filter based on request header information.
|
||||||
|
|
||||||
<CodeBlock example="application" file="vh.rs" section="vh" />
|
<CodeBlock example="application" file="vh.rs" section="vh" />
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@ async fn main() -> std::io::Result<()> {
|
|||||||
App::new()
|
App::new()
|
||||||
.service(
|
.service(
|
||||||
web::scope("/")
|
web::scope("/")
|
||||||
.guard(guard::Header("Host", "www.rust-lang.org"))
|
.guard(guard::Host("www.rust-lang.org"))
|
||||||
.route("", web::to(|| async { HttpResponse::Ok().body("www") })),
|
.route("", web::to(|| async { HttpResponse::Ok().body("www") })),
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
web::scope("/")
|
web::scope("/")
|
||||||
.guard(guard::Header("Host", "users.rust-lang.org"))
|
.guard(guard::Host("users.rust-lang.org"))
|
||||||
.route("", web::to(|| async { HttpResponse::Ok().body("user") })),
|
.route("", web::to(|| async { HttpResponse::Ok().body("user") })),
|
||||||
)
|
)
|
||||||
.route("/", web::to(HttpResponse::Ok))
|
.route("/", web::to(HttpResponse::Ok))
|
||||||
|
Loading…
Reference in New Issue
Block a user