Perlbal-Plugin-ForwardedFor

 view release on metacpan or  search on metacpan

META.yml  view on Meta::CPAN

---
abstract: 'Rename the X-Forwarded-For header in Perlbal'
author:
  - 'Sawyer X <xsawyerx@cpan.org>'
build_requires:
  Test::More: 0
configure_requires:
  Module::Build: 0.36
generated_by: 'Module::Build version 0.3603'
license: perl
meta-spec:
  url: http://module-build.sourceforge.net/META-spec-v1.4.html

README  view on Meta::CPAN

NAME
    Perlbal::Plugin::ForwardedFor - Rename the X-Forwarded-For header in
    Perlbal

VERSION
    Version 0.02

SYNOPSIS
    This plugin changes the header Perlbal will use to delcare itself as a
    proxy.

    Usually Perlbal will - perl RFC - add itself to X-Forwarded-For, but
    this plugins allows you to change that to any header you want, so you
    could differ Perlbal from other possible proxies the user might have.

    In your Perlbal configuration:

        LOAD ForwardedFor

        CREATE SERVICE http_balancer
          SET role      = reverse_proxy
          SET pool      = machines

README  view on Meta::CPAN

SUBROUTINES/METHODS
  load
    Register a global hook and check for configuration problems.

  register
    Register a service hook to run a callback to rewrite the header.

  rewrite_header
    The function that is called as the callback.

    Rewrites the *X-Forwarded-For* to whatever header name you specified in
    the configuration file.

AUTHOR
    Sawyer X, "<xsawyerx at cpan.org>"

BUGS
    This plugin is on Github and you can file issues on:

    <http://github.com/xsawyerx/perlbal-plugin-forwardedfor/issues>

lib/Perlbal/Plugin/ForwardedFor.pm  view on Meta::CPAN

        'backend_client_assigned',
        sub { rewrite_header( @_, $target_header ) },
    );

    return 1;
} 

sub rewrite_header {
    my ( $svc, $target_header ) = @_;
    my $headers     = $svc->{'req_headers'};
    my $header_name = 'X-Forwarded-For';
    my $forwarded   = $headers->header($header_name);
    my $DELIMITER   = q{, };
    my $EMPTY       = q{};

    my @ips = split /$DELIMITER/, $forwarded;
    my $ip  = pop @ips;

    $headers->header( $target_header, $ip );

    if (@ips) {

lib/Perlbal/Plugin/ForwardedFor.pm  view on Meta::CPAN


    return 0;
}

1;

__END__

=head1 NAME

Perlbal::Plugin::ForwardedFor - Rename the X-Forwarded-For header in Perlbal

=head1 VERSION

Version 0.02

=head1 SYNOPSIS

This plugin changes the header Perlbal will use to delcare itself as a proxy.

Usually Perlbal will - perl RFC - add itself to X-Forwarded-For, but this
plugins allows you to change that to any header you want, so you could differ
Perlbal from other possible proxies the user might have.

In your Perlbal configuration:

    LOAD ForwardedFor

    CREATE SERVICE http_balancer
      SET role      = reverse_proxy
      SET pool      = machines

lib/Perlbal/Plugin/ForwardedFor.pm  view on Meta::CPAN

Register a global hook and check for configuration problems.

=head2 register

Register a service hook to run a callback to rewrite the header.

=head2 rewrite_header

The function that is called as the callback.

Rewrites the I<X-Forwarded-For> to whatever header name you specified in the
configuration file.

=head1 AUTHOR

Sawyer X, C<< <xsawyerx at cpan.org> >>

=head1 BUGS

This plugin is on Github and you can file issues on:

t/rewrite_header.t  view on Meta::CPAN


sub new { return bless {}, shift }

sub header {
    my ( $self, $key, $value ) = @_;

    if ( $key && $value ) {
        is( $key,   'MySpecialHeader', 'Setting new header'               );
        is( $value, '1.1.1.1',         'Setting correct value for header' );
    } elsif ($key) {
        is( $key, 'X-Forwarded-For',   'Correct old header in TestHeader' );
    }

    return '1.1.1.1';
}

package main;
use strict;
use warnings;

use Test::More tests => 5;



( run in 0.410 second using v1.01-cache-2.11-cpan-4e96b696675 )