aboutsummaryrefslogtreecommitdiff
path: root/src/response.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-12-23 07:51:48 +0100
committerMartin Fischer <martin@push-f.com>2021-12-23 23:05:10 +0100
commit460150079f7bbf868c42d0c3c10119a15e9d6b84 (patch)
treea7bea00b74670dad4ee663da7cbbb2a77d658496 /src/response.rs
parent62fa053b4be22cdedfb4ffeb3045e9fc2d854292 (diff)
format with cargo fmt
Diffstat (limited to 'src/response.rs')
-rw-r--r--src/response.rs34
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);
}