use cookie crate instead of strings
This commit is contained in:
@@ -5,10 +5,12 @@ authors = ["Jared Burce <jaredr@gmail.com>"]
|
|||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
cookie = "0.13"
|
||||||
futures = "0.3"
|
futures = "0.3"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pretty_env_logger = "0.4"
|
pretty_env_logger = "0.4"
|
||||||
sessions = { version = "0.0.2", features = ["fs-store", "nanoid", "tokio"] }
|
sessions = { version = "0.0.2", features = ["fs-store", "nanoid", "tokio"] }
|
||||||
|
time = "0.2"
|
||||||
tokio = { version = "0.2", features = ["macros"] }
|
tokio = { version = "0.2", features = ["macros"] }
|
||||||
warp = "0.2"
|
warp = "0.2"
|
||||||
webrtc-unreliable = "0.4"
|
webrtc-unreliable = "0.4"
|
||||||
|
|||||||
10
src/main.rs
10
src/main.rs
@@ -1,10 +1,11 @@
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
|
use cookie::{Cookie, SameSite};
|
||||||
use log::{info, trace};
|
use log::{info, trace};
|
||||||
use warp::{Filter, Rejection, Reply};
|
use warp::{Filter, Rejection, Reply};
|
||||||
use warp::http::{StatusCode, Uri};
|
use warp::http::{StatusCode, Uri};
|
||||||
|
|
||||||
const SESSION_HEADER: &'static str = "Session";
|
const SESSION_HEADER: &'static str = "Spectrum-Session";
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
@@ -96,7 +97,12 @@ async fn handle_no_session(err: Rejection) -> Result<impl Reply, Rejection> {
|
|||||||
match err.find() {
|
match err.find() {
|
||||||
Some(NoSession) => Ok(warp::reply::with_header(warp::redirect::temporary(Uri::from_static("/user")),
|
Some(NoSession) => Ok(warp::reply::with_header(warp::redirect::temporary(Uri::from_static("/user")),
|
||||||
"Set-Cookie",
|
"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)
|
_ => Err(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user