Fix ratelimiting example

Geeze, that code's ancient!  How long was that broken?
This commit is contained in:
Emii Tatsuo 2020-12-01 17:13:54 -05:00
parent b265ae985c
commit 3e2865de12
Signed by: Emi
GPG key ID: 68FAB2E2E6DFC98B

View file

@ -17,21 +17,18 @@ async fn main() -> Result<()> {
.await .await
} }
fn handle_request(request: Request) -> BoxFuture<'static, Result<Response>> { async fn handle_request(request: Request) -> Result<Response> {
async move { let mut document = Document::new();
let mut document = Document::new();
if let Some("limit") = request.trailing_segments().get(0).map(String::as_str) { if let Some("limit") = request.trailing_segments().get(0).map(String::as_str) {
document.add_text("You're on a rate limited page!") document.add_text("You're on a rate limited page!")
.add_text("You can only access this page twice per minute"); .add_text("You can only access this page twice per minute");
} else { } else {
document.add_text("You're on a normal page!") document.add_text("You're on a normal page!")
.add_text("You can access this page as much as you like."); .add_text("You can access this page as much as you like.");
}
document.add_blank_line()
.add_link("/limit", "Go to rate limited page")
.add_link("/", "Go to a page that's not rate limited");
Ok(Response::document(document))
} }
.boxed() document.add_blank_line()
.add_link("/limit", "Go to rate limited page")
.add_link("/", "Go to a page that's not rate limited");
Ok(document.into())
} }