|
|
|
@ -12,7 +12,7 @@ async fn main() -> Result<()> {
|
|
|
|
|
|
|
|
|
|
Server::new()
|
|
|
|
|
.add_route("/", handle_request)
|
|
|
|
|
.ratelimit("/limit", 2, Duration::from_secs(60))
|
|
|
|
|
.ratelimit("/limit", 2, Duration::from_secs(10))
|
|
|
|
|
.serve_ip("localhost:1965")
|
|
|
|
|
.await
|
|
|
|
|
}
|
|
|
|
@ -22,7 +22,7 @@ async fn handle_request(request: Request) -> Result<Response> {
|
|
|
|
|
|
|
|
|
|
if let Some("limit") = request.trailing_segments().get(0).map(String::as_str) {
|
|
|
|
|
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 every 10 seconds");
|
|
|
|
|
} else {
|
|
|
|
|
document.add_text("You're on a normal page!")
|
|
|
|
|
.add_text("You can access this page as much as you like.");
|
|
|
|
|