The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Apache2::ASP::RequestFilter - Filter incoming requests

SYNOPSIS

  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>

DESCRIPTION

Subclass Apache2::ASP::RequestFilter to instantly apply rules to incoming requests.

These RequestFilters also work for testing via Apache2::ASP::Test::Base and Apache2::ASP::API.

RequestFilters vs TransHandlers

The difference between RequestFilters and Apache2::ASP::TransHandlers 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 Apache2::RequestRec $r and the Apache2::ASP::Config (and only then if you load it up yourself via Apache2::ASP::ConfigLoader.

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 Apache2::ASP::API.

ABSTRACT METHODS

run( $self, Apache2::ASP::HTTPContext $context )

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.

BUGS

It's possible that some bugs have found their way into this release.

Use RT http://rt.cpan.org/NoAuth/Bugs.html?Dist=Apache2-ASP to submit bug reports.

HOMEPAGE

Please visit the Apache2::ASP homepage at http://www.devstack.com/ to see examples of Apache2::ASP in action.

AUTHOR

John Drago <jdrago_999@yahoo.com>

COPYRIGHT AND LICENSE

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.