From 17a06100943a0c68ade43a2277671101ae722209 Mon Sep 17 00:00:00 2001 From: Prabir Shrestha Date: Mon, 25 May 2020 11:58:50 -0700 Subject: [PATCH] add cookie path --- examples/cookies.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/examples/cookies.rs b/examples/cookies.rs index 1030b78d2..687f0b751 100644 --- a/examples/cookies.rs +++ b/examples/cookies.rs @@ -5,18 +5,22 @@ use tide::{Request, StatusCode}; /// Tide will use the the `Cookies`'s `Extract` implementation to build this parameter. /// async fn retrieve_cookie(cx: Request<()>) -> tide::Result { - Ok(format!("hello cookies: {:?}", cx.cookie("hello").unwrap())) + if let Some(cookie) = cx.cookie("hello") { + Ok(format!("hello cookies: {:?}", cookie)) + } else { + Ok("cookies not found. navigate to /set or /remove".to_owned()) + } } async fn insert_cookie(_req: Request<()>) -> tide::Result { let mut res = tide::Response::new(StatusCode::Ok); - res.insert_cookie(Cookie::new("hello", "world")); + res.insert_cookie(Cookie::build("hello", "world").path("/").finish()); Ok(res) } async fn remove_cookie(_req: Request<()>) -> tide::Result { let mut res = tide::Response::new(StatusCode::Ok); - res.remove_cookie(Cookie::named("hello")); + res.remove_cookie(Cookie::build("hello", "").path("/").finish()); Ok(res) }