Skip Menu |

This queue is for tickets about the BS-HTTPD CPAN distribution.

Report information
The Basics
Id: 50458
Status: resolved
Priority: 0/
Queue: BS-HTTPD

People
Owner: Nobody in particular
Requestors: michael [...] dynamine.net
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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
It's already implemented and in the documentation of AnyEvent::HTTPD: In the EVENTS section you will find: Also every request also emits the "request" event, with the same arguments and semantics, you can use this to implement your own request multiplexing. You can use that event to capture requests before any paths related events are made. Greetings, Robin
Subject: Re: [rt.cpan.org #50458] Feature request: register special handler that is executed before any path-specific ones
Date: Wed, 14 Oct 2009 10:39:11 -0700
To: bug-BS-HTTPD [...] rt.cpan.org
From: "Michael S. Fischer" <michael [...] dynamine.net>
Ah, ok. I obviously did not see that. Perhaps it would be useful to add "or access control" to the end of the sentence. Thanks!