cookie_options/
cookie_options.rs1use warp::{Filter, Rejection};
2use warp_sessions::{CookieOptions, MemoryStore, SameSiteCookieOption, SessionWithStore};
3
4#[tokio::main]
5async fn main() {
6 let session_store = MemoryStore::new();
7
8 let route = warp::get()
9 .and(warp::path!("test"))
10 .and(warp_sessions::request::with_session(
11 session_store,
12 Some(CookieOptions {
13 cookie_name: "sid",
14 cookie_value: None,
15 max_age: Some(600),
16 domain: Some("domain.com".to_string()),
17 path: Some("/test".to_string()),
18 secure: true,
19 http_only: true,
20 same_site: Some(SameSiteCookieOption::Strict),
21 }),
22 ))
23 .and_then(
24 move |session_with_store: SessionWithStore<MemoryStore>| async move {
25 Ok::<_, Rejection>((
26 warp::reply::html("<html></html>".to_string()),
27 session_with_store,
28 ))
29 },
30 )
31 .untuple_one()
32 .and_then(warp_sessions::reply::with_session);
33
34 let port = 8080;
36 println!("starting server listening on ::{}", port);
37 warp::serve(route).run(([0, 0, 0, 0], port)).await;
38}