This repository has been archived by the owner on Oct 29, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revamp the flow to fit current routing handler. Cookie flow and convertion are improved in this commit too.
- Loading branch information
Showing
8 changed files
with
102 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
use obsidian::{context::Context, App}; | ||
use obsidian::middleware::cookie_parser::CookieParser; | ||
use cookie::Cookie; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let mut app: App = App::new(); | ||
let addr = ([127, 0, 0, 1], 3000).into(); | ||
|
||
app.get("/", |ctx: Context| async { | ||
if let Some(cookies) = ctx.cookie("cookie_name") { | ||
let cookies2 = ctx.cookie("cookie_name2").expect("cookie_name2 should be set"); | ||
let response = format!("{}={}; {}={};", cookies.name(), cookies.value(), cookies2.name(), cookies2.value()); | ||
|
||
ctx | ||
.build(response) | ||
.ok() | ||
} | ||
else { | ||
ctx | ||
.build("Set cookies!") | ||
.with_cookie(Cookie::new("cookie_name", "cookie_value")) | ||
.with_cookie(Cookie::new("cookie_name2", "cookie_value2")) | ||
.ok() | ||
} | ||
}); | ||
|
||
let cookie_parser = CookieParser::new(); | ||
app.use_service(cookie_parser); | ||
|
||
app.listen(&addr, || { | ||
println!("server is listening to {}", &addr); | ||
}) | ||
.await; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters