File tree Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Expand file tree Collapse file tree 1 file changed +7
-3
lines changed Original file line number Diff line number Diff line change @@ -5,18 +5,22 @@ use tide::{Request, StatusCode};
55/// Tide will use the the `Cookies`'s `Extract` implementation to build this parameter.
66///
77async fn retrieve_cookie ( cx : Request < ( ) > ) -> tide:: Result < String > {
8- Ok ( format ! ( "hello cookies: {:?}" , cx. cookie( "hello" ) . unwrap( ) ) )
8+ if let Some ( cookie) = cx. cookie ( "hello" ) {
9+ Ok ( format ! ( "hello cookies: {:?}" , cookie) )
10+ } else {
11+ Ok ( "cookies not found. navigate to /set or /remove" . to_owned ( ) )
12+ }
913}
1014
1115async fn insert_cookie ( _req : Request < ( ) > ) -> tide:: Result {
1216 let mut res = tide:: Response :: new ( StatusCode :: Ok ) ;
13- res. insert_cookie ( Cookie :: new ( "hello" , "world" ) ) ;
17+ res. insert_cookie ( Cookie :: build ( "hello" , "world" ) . path ( "/" ) . finish ( ) ) ;
1418 Ok ( res)
1519}
1620
1721async fn remove_cookie ( _req : Request < ( ) > ) -> tide:: Result {
1822 let mut res = tide:: Response :: new ( StatusCode :: Ok ) ;
19- res. remove_cookie ( Cookie :: named ( "hello" ) ) ;
23+ res. remove_cookie ( Cookie :: build ( "hello" , "" ) . path ( "/" ) . finish ( ) ) ;
2024 Ok ( res)
2125}
2226
You can’t perform that action at this time.
0 commit comments