From 9c5d0912ec3e8c2689e1ab23d4be4fdd0e03a9cc Mon Sep 17 00:00:00 2001 From: Jeb Rosen Date: Thu, 22 Aug 2019 14:18:44 -0700 Subject: [PATCH] Explain how to resolve the One-At-A-Time Cookies problem when using FlashMessage. Fixes #1090. --- site/guide/4-requests.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/site/guide/4-requests.md b/site/guide/4-requests.md index 3338292e..f26fd3d8 100644 --- a/site/guide/4-requests.md +++ b/site/guide/4-requests.md @@ -623,6 +623,25 @@ guards: 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 A route can specify the data format it is willing to accept or respond with by