Apache2-Connection-XForwardedFor

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

--- #YAML:1.0
name:               Apache2-Connection-XForwardedFor
version:            0.02
abstract:           Sets the connection remote_ip to X-Forwarded-For header
author:  []
license:            unknown
distribution_type:  module
configure_requires:
    ExtUtils::MakeMaker:  0
build_requires:
    ExtUtils::MakeMaker:  0
requires:
    mod_perl2:  2.000005
no_index:

README  view on Meta::CPAN

Apache2::Connection::XFUosrewrarCdoendtFroirb(u3t)ed PerAlpaDcohceu2m:e:nCtoantnieocntion::XForwardedFor(3)



NNAAMMEE
       Apache2::Connection::XForwardedFor - Sets the connection remote_ip to
       X-Forwarded-For header

SSYYNNOOPPSSIISS
        PerlPostReadRequestHandler Apache2::Connection::XForwardedFor

       Meanwhile in another mod_perl handler...

        $client_ip = $r->connection->remote_ip;

DDEESSCCRRIIPPTTIIOONN
       This simple module takes the X-Forwarded-For header value and sets the
       remote_ip attribute of the connection object with that ip.  This module
       is meant to be used with reverse proxies where the proxy sets the
       header to the ip of the http client.

       This module doesn't have any fancy features like similar modules, it is
       meant to be short and to the point, and have some test coverage.

SSEEEE AALLSSOO
       Apache2::Connection

lib/Apache2/Connection/XForwardedFor.pm  view on Meta::CPAN

package Apache2::Connection::XForwardedFor;

use strict;
use warnings;

=head1 NAME

Apache2::Connection::XForwardedFor - Sets the connection remote_ip to X-Forwarded-For header

=head1 SYNOPSIS

 PerlPostReadRequestHandler Apache2::Connection::XForwardedFor

Meanwhile in another mod_perl handler...

 $client_ip = $r->connection->remote_ip;

=head1 DESCRIPTION

This simple module takes the X-Forwarded-For header value and sets the
remote_ip attribute of the connection object with that ip.  This module is
meant to be used with reverse proxies where the proxy sets the header to the
ip of the http client.

This module doesn't have any fancy features like similar modules, it is meant
to be short and to the point, and have some test coverage.

=cut

our $VERSION = 0.02;

use Apache2::Connection ();
use Apache2::RequestRec ();
use Apache2::Const -compile => qw( DECLINED );
use APR::Table ();

sub handler {
    my $r = shift;

    # unset the X-Forwarded header and set the connection remote_ip
    if ( defined $r->headers_in->{'X-Forwarded-For'} ) {
        $r->connection->remote_ip( $r->headers_in->{'X-Forwarded-For'} );
        $r->headers_in->unset('X-Forwarded-For');
    }

    return Apache2::Const::DECLINED;
}

1;

=head1 SEE ALSO

L<Apache2::Connection>



( run in 0.465 second using v1.01-cache-2.11-cpan-26ccb49234f )