1
0
mirror of https://github.com/actix/actix-extras.git synced 2024-11-28 01:32:57 +01:00

update cors doc string

This commit is contained in:
Nikolay Kim 2018-04-09 21:39:32 -07:00
parent 2881859400
commit 23eea54776

View File

@ -10,8 +10,8 @@
//! 3. Call [finish](struct.Cors.html#method.finish) to retrieve the constructed backend. //! 3. Call [finish](struct.Cors.html#method.finish) to retrieve the constructed backend.
//! //!
//! Cors middleware could be used as parameter for `App::middleware()` or //! Cors middleware could be used as parameter for `App::middleware()` or
//! `ResourceHandler::middleware()` methods. But you have to use `Cors::register()` method to //! `ResourceHandler::middleware()` methods. But you have to use
//! support *preflight* OPTIONS request. //! `Cors::for_app()` method to support *preflight* OPTIONS request.
//! //!
//! //!
//! # Example //! # Example
@ -19,7 +19,7 @@
//! ```rust //! ```rust
//! # extern crate actix_web; //! # extern crate actix_web;
//! use actix_web::{http, App, HttpRequest, HttpResponse}; //! use actix_web::{http, App, HttpRequest, HttpResponse};
//! use actix_web::middleware::cors; //! use actix_web::middleware::cors::Cors;
//! //!
//! fn index(mut req: HttpRequest) -> &'static str { //! fn index(mut req: HttpRequest) -> &'static str {
//! "Hello world" //! "Hello world"
@ -27,19 +27,17 @@
//! //!
//! fn main() { //! fn main() {
//! let app = App::new() //! let app = App::new()
//! .resource("/index.html", |r| { //! .configure(|app| Cors::for_app(app) // <- Construct CORS middleware builder
//! cors::Cors::build() // <- Construct CORS middleware //! .allowed_origin("https://www.rust-lang.org/")
//! .allowed_origin("https://www.rust-lang.org/") //! .allowed_methods(vec!["GET", "POST"])
//! .allowed_methods(vec!["GET", "POST"]) //! .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT])
//! .allowed_headers(vec![http::header::AUTHORIZATION, http::header::ACCEPT]) //! .allowed_header(http::header::CONTENT_TYPE)
//! .allowed_header(http::header::CONTENT_TYPE) //! .max_age(3600)
//! .max_age(3600) //! .resource("/index.html", |r| {
//! .finish() //! r.method(http::Method::GET).f(|_| HttpResponse::Ok());
//! .register(r); // <- Register CORS middleware //! r.method(http::Method::HEAD).f(|_| HttpResponse::MethodNotAllowed());
//! r.method(http::Method::GET).f(|_| HttpResponse::Ok()); //! })
//! r.method(http::Method::HEAD).f(|_| HttpResponse::MethodNotAllowed()); //! .register());
//! })
//! .finish();
//! } //! }
//! ``` //! ```
//! In this example custom *CORS* middleware get registered for "/index.html" endpoint. //! In this example custom *CORS* middleware get registered for "/index.html" endpoint.