From 18ae2e0f9ac4b543597dafb5f4c2fe4f4b0147ab Mon Sep 17 00:00:00 2001 From: Jared Burce Date: Wed, 25 Mar 2020 16:24:48 -0700 Subject: [PATCH] use cookie crate instead of strings --- Cargo.toml | 2 ++ src/main.rs | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1c64b21..b50c88e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,10 +5,12 @@ authors = ["Jared Burce "] edition = "2018" [dependencies] +cookie = "0.13" futures = "0.3" log = "0.4" pretty_env_logger = "0.4" sessions = { version = "0.0.2", features = ["fs-store", "nanoid", "tokio"] } +time = "0.2" tokio = { version = "0.2", features = ["macros"] } warp = "0.2" webrtc-unreliable = "0.4" diff --git a/src/main.rs b/src/main.rs index 14e16ef..97d2367 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,10 +1,11 @@ use std::collections::HashMap; +use cookie::{Cookie, SameSite}; use log::{info, trace}; use warp::{Filter, Rejection, Reply}; use warp::http::{StatusCode, Uri}; -const SESSION_HEADER: &'static str = "Session"; +const SESSION_HEADER: &'static str = "Spectrum-Session"; #[tokio::main] async fn main() { @@ -96,7 +97,12 @@ async fn handle_no_session(err: Rejection) -> Result { match err.find() { Some(NoSession) => Ok(warp::reply::with_header(warp::redirect::temporary(Uri::from_static("/user")), "Set-Cookie", - format!("{}={}; Max-Age=31536000; SameSite=Lax", SESSION_HEADER, 5))), + Cookie::build(SESSION_HEADER, 5.to_string()) + .max_age(time::Duration::seconds(60 * 60 * 24 * 365)) + .max_age(time::Duration::seconds(10)) + .same_site(SameSite::Lax) + .finish() + .to_string())), _ => Err(err) } }