A better version of the JavaScript-less Cookie Monster, one which curl
can work with too, with the appropriate flags:
fn decide(request: Request) -> Response? {
let response = ResponseBuilder.new();
if request.cookie("x-bot-challenge") == "passed" {
response.status(HTTP_STATUS_MISDIRECTED_REQUEST);
} else {
response.header("content-type", "text/html");
response.header("set-cookie", "x-bot-challenge=passed;path=/");
response.header("location", request.path());
response.status(HTTP_STATUS_MOVED_PERMANENTLY);
response.body_from_string("<!doctype html>
<html>
<head>
<title>Cookie monster!</title>
</head>
<body>
<p>This is an automated check to get rid of most bots. You should be redirected to the real page soon.</p>
</body>");
}
Some(response.build())
}
=>
❯ curl -iL http://localhost:42069/foobar -b ""
HTTP/1.1 301 Moved Permanently
content-type: text/html
set-cookie: x-bot-challenge=passed;path=/
location: foobar
content-length: 194
date: Fri, 25 Jul 2025 14:51:17 GMT
HTTP/1.1 421 Misdirected Request
content-type: application/octet-stream
content-length: 0
date: Fri, 25 Jul 2025 14:51:17 GMT
Not completely sure about that location
header, though. But something like this should do the trick!
Or the <meta http-equiv=refresh>
, as long as it is bound to browsers only, and not for other tools.