|
19 | 19 | //! stable. See
|
20 | 20 | //! [installation instructions](https://rocket.rs/guide/getting-started/#installing-rust).
|
21 | 21 | //!
|
22 |
| -//! In particular, `rocket_cors` is currently targetted for `nightly-2017-07-21`. Newer nightlies |
23 |
| -//! might work, but it's not guaranteed. |
| 22 | +//! In particular, `rocket_cors` is currently targetted for the latest `nightly`. Older nightlies |
| 23 | +//! might work, but they are subject to the minimum that Rocket sets. |
24 | 24 | //!
|
25 | 25 | //! ## Installation
|
26 | 26 | //!
|
|
59 | 59 | //!
|
60 | 60 | //! ### `Cors` Struct
|
61 | 61 | //!
|
62 |
| -//! The [`Cors` struct](struct.Cors.html) contains the settings for CORS requests to be validated |
| 62 | +//! The [`Cors` struct](Cors) contains the settings for CORS requests to be validated |
63 | 63 | //! and for responses to be generated. Defaults are defined for every field in the struct, and
|
64 |
| -//! are documented on the [`Cors` struct](struct.Cors.html) page. You can also deserialize |
| 64 | +//! are documented on the [`Cors` struct](Cors) page. You can also deserialize |
65 | 65 | //! the struct from some format like JSON, YAML or TOML when the default `serialization` feature
|
66 | 66 | //! is enabled.
|
67 | 67 | //!
|
|
97 | 97 | //! However, you can only have one set of settings that must apply to all routes. You cannot opt
|
98 | 98 | //! any route out of CORS checks.
|
99 | 99 | //!
|
100 |
| -//! To use this, simply create a [`Cors` struct](struct.Cors.html) and then |
| 100 | +//! To use this, simply create a [`Cors` struct](Cors) and then |
101 | 101 | //! [`attach`](https://api.rocket.rs/rocket/struct.Rocket.html#method.attach) it to Rocket.
|
102 | 102 | //!
|
103 | 103 | //! ```rust,no_run
|
|
144 | 144 | //!
|
145 | 145 | //! You will have to do the following:
|
146 | 146 | //!
|
147 |
| -//! - Create a [`Cors` struct](struct.Cors.html) and during Rocket's ignite, add the struct to |
| 147 | +//! - Create a [`Cors` struct](Cors) and during Rocket's ignite, add the struct to |
148 | 148 | //! Rocket's [managed state](https://rocket.rs/guide/state/#managed-state).
|
149 | 149 | //! - For all the routes that you want to enforce CORS on, you can mount either some
|
150 |
| -//! [catch all route](fn.catch_all_options_routes.html) or define your own route for the OPTIONS |
| 150 | +//! [catch all route](catch_all_options_routes) or define your own route for the OPTIONS |
151 | 151 | //! verb.
|
152 | 152 | //! - Then in all the routes you want to enforce CORS on, add a
|
153 | 153 | //! [Request Guard](https://rocket.rs/guide/requests/#request-guards) for the
|
154 |
| -//! [`Guard`](struct.Guard.html) struct in the route arguments. You should not wrap this in an |
| 154 | +//! [`Guard`](Guard) struct in the route arguments. You should not wrap this in an |
155 | 155 | //! `Option` or `Result` because the guard will let non-CORS requests through and will take over
|
156 | 156 | //! error handling in case of errors.
|
157 | 157 | //! - In your routes, to add CORS headers to your responses, use the appropriate functions on the
|
158 |
| -//! [`Guard`](struct.Guard.html) for a `Response` or a `Responder`. |
| 158 | +//! [`Guard`](Guard) for a `Response` or a `Responder`. |
159 | 159 | //!
|
160 | 160 | //! ```rust,no_run
|
161 | 161 | //! #![feature(plugin)]
|
|
252 | 252 | //! Alternatively, you can create a `Cors` struct directly in the route.
|
253 | 253 | //! - Your routes _might_ need to have a `'r` lifetime and return `impl Responder<'r>`. See below.
|
254 | 254 | //! - Using the `Cors` struct, use either the
|
255 |
| -//! [`respond_owned`](struct.Cors.html#method.respond_owned) or |
256 |
| -//! [`respond_borrowed`](struct.Cors.html#method.respond_borrowed) function and pass in a handler |
| 255 | +//! [`respond_owned`](Cors#method.respond_owned) or |
| 256 | +//! [`respond_borrowed`](Cors#method.respond_borrowed) function and pass in a handler |
257 | 257 | //! that will be executed once CORS validation is successful.
|
258 |
| -//! - Your handler will be passed a [`Guard`](struct.Guard.html) which you will have to use to |
| 258 | +//! - Your handler will be passed a [`Guard`](Guard) which you will have to use to |
259 | 259 | //! add CORS headers into your own response.
|
260 | 260 | //! - You will have to manually define your own `OPTIONS` routes.
|
261 | 261 | //!
|
|
352 | 352 | //!
|
353 | 353 | //! /// Using a borrowed Cors
|
354 | 354 | //! #[get("/")]
|
355 |
| -//! fn borrowed<'r>(options: State<'r, Cors>) -> impl Responder<'r> { |
| 355 | +//! fn borrowed(options: State<Cors>) -> impl Responder { |
356 | 356 | //! options.inner().respond_borrowed(
|
357 | 357 | //! |guard| guard.responder("Hello CORS"),
|
358 | 358 | //! )
|
359 | 359 | //! }
|
360 | 360 | //!
|
361 | 361 | //! /// Using a `Response` instead of a `Responder`. You generally won't have to do this.
|
362 | 362 | //! #[get("/response")]
|
363 |
| -//! fn response<'r>(options: State<'r, Cors>) -> impl Responder<'r> { |
| 363 | +//! fn response(options: State<Cors>) -> impl Responder { |
364 | 364 | //! let mut response = Response::new();
|
365 | 365 | //! response.set_sized_body(Cursor::new("Hello CORS!"));
|
366 | 366 | //!
|
|
455 | 455 | //!
|
456 | 456 | //! /// A special struct that allows all origins
|
457 | 457 | //! ///
|
458 |
| -//! /// Note: In your real application, you might want to use something like `lazy_static` to generate |
459 |
| -//! /// a `&'static` reference to this instead of creating a new struct on every request. |
| 458 | +//! /// Note: In your real application, you might want to use something like `lazy_static` to |
| 459 | +//! /// generate a `&'static` reference to this instead of creating a new struct on every request. |
460 | 460 | //! fn cors_options_all() -> Cors {
|
461 | 461 | //! // You can also deserialize this
|
462 | 462 | //! rocket_cors::Cors {
|
|
0 commit comments