use cookie crate instead of strings

This commit is contained in:
2020-03-25 16:24:48 -07:00
parent f09b79ad69
commit 18ae2e0f9a
2 changed files with 10 additions and 2 deletions

View File

@@ -5,10 +5,12 @@ authors = ["Jared Burce <jaredr@gmail.com>"]
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"

View File

@@ -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<impl Reply, Rejection> {
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)
}
}