add max-age and date for flash cookies

This commit is contained in:
glyph 2022-03-20 16:37:53 +02:00
parent e8b9cb2cc1
commit 60539adf41
1 changed files with 10 additions and 4 deletions

View File

@ -32,13 +32,19 @@ pub trait FlashResponse {
impl FlashResponse for Response {
fn add_flash(self, flash_name: String, flash_msg: String) -> Response {
// set the flash cookie headers
self.with_additional_header("Set-Cookie", flash_name)
.with_additional_header("Set-Cookie", flash_msg)
self.with_additional_header("Set-Cookie", format!("{}; Max-Age=1", flash_name))
.with_additional_header("Set-Cookie", format!("{}; Max-Age=1", flash_msg))
}
fn reset_flash(self) -> Response {
// set blank cookies to clear the flash msg from the previous request
self.with_additional_header("Set-Cookie", "flash_name=")
.with_additional_header("Set-Cookie", "flash_msg=")
self.with_additional_header(
"Set-Cookie",
"flash_name=; Max-Age=0; Expires=Fri, 21 Aug 1987 12:00:00 UTC",
)
.with_additional_header(
"Set-Cookie",
"flash_msg=; Max-Age=0; Expires=Fri, 21 Aug 1987 12:00:00 UTC",
)
}
}