| Apache2::ASP::RequestFilter - Filter incoming requests |
Apache2::ASP::RequestFilter - Filter incoming requests
package My::MemberFilter; use strict; use warnings 'all'; use base 'Apache2::ASP::RequestFilter'; use vars __PACKAGE__->VARS; sub run { my ($self, $context) = @_; if( $Session->{is_logged_in} ) { # The user is logged in - we can ignore this request: return $Response->Declined; } else { # The user must authenticate first: $Session->{validation_errors} = { general => "You must log in first" }; return $Response->Redirect("/login/"); }# end if() } 1;# return true:
Then, in your apache2-asp-config.xml:
<config>
...
<web>
...
<request_filters>
<filter>
<uri_match>/members/*</uri_match>
<class>My::MemberFilter</class>
</filter>
...
</request_filters>
</web>
...
</config>
Subclass Apache2::ASP::RequestFilter to instantly apply rules to incoming
requests.
These RequestFilters also work for testing via the Apache2::ASP::Test::Base manpage and the Apache2::ASP::API manpage.
The difference between RequestFilters and the Apache2::ASP::TransHandler manpages is that within a RequestFilter, you have access to all of the normal ASP objects ($Request, $Response, $Session, etc).
In a TransHandler, you only have access to the the Apache2::RequestRec manpage $r and the
the Apache2::ASP::Config manpage (and only then if you load it up yourself via the Apache2::ASP::ConfigLoader manpage.
NOTE: - TransHandlers are configured in the httpd.conf and are only executed
in a real Apache2 httpd environment. They are not executed during testing or via
the Apache2::ASP::API manpage.
Return -1 (or $Response->Declined) to allow the current RequestFilter to be ignored.
Returning anything else...
return $Response->Redirect("/unauthorized/");
...results in the termination of the current request right away.
It's possible that some bugs have found their way into this release.
Use RT http://rt.cpan.org/NoAuth/Bugs.html to submit bug reports.
Please visit the Apache2::ASP homepage at http://www.devstack.com/ to see examples of Apache2::ASP in action.
John Drago <jdrago_999@yahoo.com>
Copyright 2007 John Drago, All rights reserved.
This software is free software. It may be used and distributed under the same terms as Perl itself.
| Apache2::ASP::RequestFilter - Filter incoming requests |