test-psgi.pm 1.94 KB
Newer Older
Xavier Guimard's avatar
Xavier Guimard committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
package LLNG::Mirror;

use strict;

our @ISA = ('Lemonldap::NG::Handler::PSGI');

our $defaultIni = {
    configStorage       => { type => 'File', dirName => 't' },
    localSessionStorage => '',
    logLevel            => 'error',
    https               => 0,
};

sub new {
    my $self = Lemonldap::NG::Handler::PSGI->new();
    $self->init($defaultIni);
    bless $self, $_[0];
}

sub handler {
    my ( $self, $req ) = @_;
    my $h = $req->headers->as_string;
    return [ 200, [ 'Content-Type' => 'text/plain' ], [$h] ];
}

package main;

BEGIN {
    use_ok('Lemonldap::NG::Handler::PSGI');
    count(1);
}
my $m   = LLNG::Mirror->new;
my $app = $m->run;

sub mirror {
    my (%args) = @_;
    return $app->(
        {
            'HTTP_ACCEPT' => $args{accept}
              || 'application/json, text/plain, */*',
            'HTTP_ACCEPT_LANGUAGE' => 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3',
            'HTTP_CACHE_CONTROL'   => 'max-age=0',
            ( $args{cookie} ? ( HTTP_COOKIE => $args{cookie} ) : () ),
            'HTTP_HOST' => $args{host} || 'test1.example.com',
            'HTTP_USER_AGENT' =>
              'Mozilla/5.0 (VAX-4000; rv:36.0) Gecko/20350101 Firefox',
            'PATH_INFO' => $args{path} || '/',
            ( $args{referer} ? ( REFERER => $args{referer} ) : () ),
            'REMOTE_ADDR' => '127.0.0.1',
            (
                $args{remote_user}
                ? ( 'REMOTE_USER' => $args{remote_user} )
                : ()
            ),
            'REQUEST_METHOD' => $args{method} || 'GET',
Xavier Guimard's avatar
Xavier Guimard committed
56
            'REQUEST_URI'    => ( $args{path} || '/' )
Xavier Guimard's avatar
Xavier Guimard committed
57 58 59 60 61 62 63 64 65 66 67 68
              . ( $args{query} ? "?$args{query}" : '' ),
            ( $args{query} ? ( QUERY_STRING => $args{query} ) : () ),
            'SCRIPT_NAME'     => '',
            'SERVER_NAME'     => 'auth.example.com',
            'SERVER_PORT'     => '80',
            'SERVER_PROTOCOL' => 'HTTP/1.1',
            ( $args{custom} ? %{ $args{custom} } : () ),
        }
    );
}

1;