CGI-Emulate-PSGI

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

0.23  2017-05-08 04:45:43 UTC

        - Respect an NPH script's HTTP status line (wu-lee) #4

0.22  2016-07-19 08:03:23 PDT
        - Do not set HTTP_PROXY (kazeburo) #14

0.21  2015-07-21 09:02:04 PDT
        - Fix to restore the selected filehandle correctly #12

0.20  2014-09-08 11:06:19 PDT
        - Add Test::Requires dependency (andk)

0.19  2014-08-31 14:04:44 JST
        - Revert #3 since it causes deep recursion when printing to STDERR
          inside CGI handler under some perl environments. #6

lib/CGI/Emulate/PSGI.pm  view on Meta::CPAN


    no warnings;
    my $environment = {
        GATEWAY_INTERFACE => 'CGI/1.1',
        HTTPS => ( ( $env->{'psgi.url_scheme'} eq 'https' ) ? 'ON' : 'OFF' ),
        SERVER_SOFTWARE => "CGI-Emulate-PSGI",
        REMOTE_ADDR     => '127.0.0.1',
        REMOTE_HOST     => 'localhost',
        REMOTE_PORT     => int( rand(64000) + 1000 ),    # not in RFC 3875
        # REQUEST_URI     => $uri->path_query,                 # not in RFC 3875
        ( map { $_ => $env->{$_} } grep { !/^psgix?\./ && $_ ne "HTTP_PROXY" } keys %$env )
    };

    return wantarray ? %$environment : $environment;
}

1;
__END__

=head1 NAME

t/06_httproxy.t  view on Meta::CPAN

use strict;
use warnings;
use CGI;
use CGI::Emulate::PSGI;
use Test::More;

my $handler = CGI::Emulate::PSGI->handler(
    sub {
        ok ! exists $ENV{HTTP_PROXY};
        print "Content-Type: text/html; charset=utf-8\r\n";
        print "Content-Length: 4\r\n";
        print "\r\n";
        print "KTKR";
    }
);

my $input = "";
open my $in, '<', \$input;
open my $errors, '>', \my $err;
my $res = $handler->(
    +{
        'psgi.input'   => $in,
        REMOTE_ADDR    => '192.168.1.1',
        REQUEST_METHOD => 'GET',
        HTTP_PROXY     => 'localhost:3128',
        'psgi.errors'  => $errors,
    }
);


is $res->[0], 200;
my $headers = +{@{$res->[1]}};


done_testing;



( run in 0.608 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )