Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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