Skip to content

Commit

Permalink
add cookie path
Browse files Browse the repository at this point in the history
  • Loading branch information
prabirshrestha committed May 25, 2020
1 parent f884167 commit cd3caa5
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions examples/cookies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> {
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 set_cookie(_req: Request<()>) -> tide::Result {
let mut res = tide::Response::new(StatusCode::Ok);
res.set_cookie(Cookie::new("hello", "world"));
res.set_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)
}

Expand Down

0 comments on commit cd3caa5

Please sign in to comment.