Subject: | Feature request: register special handler that is executed before any path-specific ones |
Date: | Tue, 13 Oct 2009 10:41:57 -0700 |
To: | bug-bs-httpd [...] rt.cpan.org |
From: | Michael S. Fischer <michael [...] dynamine.net> |
Hey Robin,
Now that you've added the client_host() and client_port() methods to
AnyEvent::HTTPD::Request, it would be very useful if we could register
a callback that gets executed before any path-specific handler. That
way, I can reject a request before it gets processed by any other
handler if the peer IP address or port (or any other aspect of the
request) is disallowed.
Example:
$httpd->reg_cb(
':begin' => sub {
# This callback always gets called first, if declared.
my ($httpd, $req) = @_;
if ($req->client_host ne '127.0.0.1') {
$req->respond([403, 'not authorized', { Content-Type =>
'text/plain' }, 'not authorized']);
$httpd->stop_request;
}
},
...
);
I've chosen ":begin" as a reserved key name, but feel free to choose a
different one if you think it makes more sense.
Thanks,
--Michael