Skip to content

Commit

Permalink
add cookie path
Browse files Browse the repository at this point in the history
  • Loading branch information
prabirshrestha committed Jun 6, 2020
1 parent 08cd01a commit 17a0610
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 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)
}

Expand Down

0 comments on commit 17a0610

Please sign in to comment.