diff options
Diffstat (limited to 'src/response.rs')
-rw-r--r-- | src/response.rs | 34 |
1 files changed, 25 insertions, 9 deletions
diff --git a/src/response.rs b/src/response.rs index c9d83a7..8035c4f 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,8 +1,12 @@ //! Provides convenience traits and functions to build HTTP responses. -use std::{convert::TryInto, fmt::Display, time::{Duration, SystemTime}}; +use std::{ + convert::TryInto, + fmt::Display, + time::{Duration, SystemTime}, +}; -use crate::http::{self, HeaderMap, StatusCode, header, response::Builder}; +use crate::http::{self, header, response::Builder, HeaderMap, StatusCode}; /// Adds convenience methods to [`Builder`]. pub trait SputnikBuilder { @@ -54,14 +58,16 @@ impl Display for Cookie { if let Some(time) = self.expires { write!(f, "; Expires={}", httpdate::fmt_http_date(time))?; } - + Ok(()) } } #[derive(Debug, PartialEq)] pub enum SameSite { - Strict, Lax, None + Strict, + Lax, + None, } impl Display for SameSite { @@ -76,7 +82,9 @@ impl Display for SameSite { /// Creates a new builder with a given Location header and status code. pub fn redirect(location: &str, code: StatusCode) -> Builder { - Builder::new().status(code).header(header::LOCATION, location) + Builder::new() + .status(code) + .header(header::LOCATION, location) } impl SputnikBuilder for Builder { @@ -93,10 +101,10 @@ impl SputnikBuilder for Builder { /// Constructs an expired cookie to delete a cookie. pub fn delete_cookie(name: &str) -> Cookie { - Cookie{ + Cookie { name: name.into(), max_age: Some(Duration::from_secs(0)), - expires: Some(SystemTime::now() - Duration::from_secs(60*60*24)), + expires: Some(SystemTime::now() - Duration::from_secs(60 * 60 * 24)), ..Default::default() } } @@ -133,8 +141,16 @@ mod tests { #[test] fn test_set_cookie() { let mut map = HeaderMap::new(); - map.set_cookie(Cookie{name: "some".into(), value: "cookie".into(), ..Default::default()}); - map.set_cookie(Cookie{name: "some".into(), value: "cookie".into(), ..Default::default()}); + map.set_cookie(Cookie { + name: "some".into(), + value: "cookie".into(), + ..Default::default() + }); + map.set_cookie(Cookie { + name: "some".into(), + value: "cookie".into(), + ..Default::default() + }); assert_eq!(map.len(), 2); } |