Explain how to resolve the One-At-A-Time Cookies problem when using FlashMessage.

Fixes #1090.
This commit is contained in:
Jeb Rosen 2019-08-22 14:18:44 -07:00
parent d98e938e1a
commit 9c5d0912ec
1 changed files with 19 additions and 0 deletions

View File

@ -623,6 +623,25 @@ guards:
fn good(custom: Custom, cookies: Cookies) { .. } fn good(custom: Custom, cookies: Cookies) { .. }
``` ```
When using request guards that modify cookies on-demand, such as
`FlashMessage`, a similar problem occurs. The fix in this case is to `drop` the
`Cookies` instance before accessing the `FlashMessage`.
```rust
#[get("/")]
fn bad(cookies: Cookies, flash: FlashMessage) {
let msg = flash.msg();
}
```
```rust
#[get("/")]
fn good(cookies: Cookies, flash: FlashMessage) {
std::mem::drop(cookies);
let msg = flash.msg();
}
```
## Format ## Format
A route can specify the data format it is willing to accept or respond with by A route can specify the data format it is willing to accept or respond with by