r16395 - in /branches/upstream/libhttp-request-ascgi-perl: ./ current/ current/examples/ current/lib/ current/lib/HTTP/ current/lib/HTTP/Request/ current/t/

eloy at users.alioth.debian.org eloy at users.alioth.debian.org
Mon Mar 3 20:45:34 UTC 2008


Author: eloy
Date: Mon Mar  3 20:45:33 2008
New Revision: 16395

URL: http://svn.debian.org/wsvn/?sc=1&rev=16395
Log:
[svn-inject] Installing original source of libhttp-request-ascgi-perl

Added:
    branches/upstream/libhttp-request-ascgi-perl/
    branches/upstream/libhttp-request-ascgi-perl/current/
    branches/upstream/libhttp-request-ascgi-perl/current/Changes
    branches/upstream/libhttp-request-ascgi-perl/current/MANIFEST
    branches/upstream/libhttp-request-ascgi-perl/current/META.yml
    branches/upstream/libhttp-request-ascgi-perl/current/Makefile.PL
    branches/upstream/libhttp-request-ascgi-perl/current/README
    branches/upstream/libhttp-request-ascgi-perl/current/examples/
    branches/upstream/libhttp-request-ascgi-perl/current/examples/daemon.pl
    branches/upstream/libhttp-request-ascgi-perl/current/examples/synopsis.pl
    branches/upstream/libhttp-request-ascgi-perl/current/lib/
    branches/upstream/libhttp-request-ascgi-perl/current/lib/HTTP/
    branches/upstream/libhttp-request-ascgi-perl/current/lib/HTTP/Request/
    branches/upstream/libhttp-request-ascgi-perl/current/lib/HTTP/Request/AsCGI.pm
    branches/upstream/libhttp-request-ascgi-perl/current/t/
    branches/upstream/libhttp-request-ascgi-perl/current/t/01use.t
    branches/upstream/libhttp-request-ascgi-perl/current/t/04io.t
    branches/upstream/libhttp-request-ascgi-perl/current/t/05env.t
    branches/upstream/libhttp-request-ascgi-perl/current/t/06response.t
    branches/upstream/libhttp-request-ascgi-perl/current/t/07forking.t
    branches/upstream/libhttp-request-ascgi-perl/current/t/08error.t

Added: branches/upstream/libhttp-request-ascgi-perl/current/Changes
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/Changes?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/Changes (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/Changes Mon Mar  3 20:45:33 2008
@@ -1,0 +1,20 @@
+This file documents the revision history for Perl extension HTTP::Request::AsCGI.
+
+0.5  2006-01-20 00:00:00 2005
+    - Fixed bug where content was overridden on 500 responses.
+
+0.4  2006-01-19 00:00:00 2005
+    - Fixed #15999 return a 500 response when message is empty, reported by Chris Dolan <cdolan at cpan.org>
+    - Fixed Status header bug
+    - Bumped HTTP::Response requirement to 1.53 and drop our own message parsing.
+
+0.3  2006-01-06 00:00:00 2005
+    - Silence uninitialized warnings when restoring %ENV
+    - Fixed dup and restore of STDIN.
+
+0.2  2005-10-31 00:55:00 2005
+    - Added test for response.
+
+0.1  2005-10-21 00:00:00 2005
+    - First release.
+

Added: branches/upstream/libhttp-request-ascgi-perl/current/MANIFEST
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/MANIFEST?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/MANIFEST (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/MANIFEST Mon Mar  3 20:45:33 2008
@@ -1,0 +1,14 @@
+Changes
+examples/daemon.pl
+examples/synopsis.pl
+lib/HTTP/Request/AsCGI.pm
+Makefile.PL
+MANIFEST			This list of files
+META.yml
+README
+t/01use.t
+t/04io.t
+t/05env.t
+t/06response.t
+t/07forking.t
+t/08error.t

Added: branches/upstream/libhttp-request-ascgi-perl/current/META.yml
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/META.yml?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/META.yml (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/META.yml Mon Mar  3 20:45:33 2008
@@ -1,0 +1,16 @@
+# http://module-build.sourceforge.net/META-spec.html
+#XXXXXXX This is a prototype!!!  It will change in the future!!! XXXXX#
+name:         HTTP-Request-AsCGI
+version:      0.5
+version_from: lib/HTTP/Request/AsCGI.pm
+installdirs:  site
+requires:
+    Carp:                          0
+    Class::Accessor:               0
+    HTTP::Request:                 0
+    HTTP::Response:                1.53
+    IO::File:                      0
+    Test::More:                    0
+
+distribution_type: module
+generated_by: ExtUtils::MakeMaker version 6.30

Added: branches/upstream/libhttp-request-ascgi-perl/current/Makefile.PL
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/Makefile.PL?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/Makefile.PL (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/Makefile.PL Mon Mar  3 20:45:33 2008
@@ -1,0 +1,16 @@
+#!perl
+
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME         => 'HTTP::Request::AsCGI',
+    VERSION_FROM => 'lib/HTTP/Request/AsCGI.pm',
+    PREREQ_PM    => {
+        Carp             => 0,
+        Class::Accessor  => 0,        
+        HTTP::Request    => 0,
+        HTTP::Response   => 1.53,
+        IO::File         => 0,
+        Test::More       => 0
+    }
+);

Added: branches/upstream/libhttp-request-ascgi-perl/current/README
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/README?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/README (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/README Mon Mar  3 20:45:33 2008
@@ -1,0 +1,86 @@
+NAME
+    HTTP::Request::AsCGI - Setup a CGI enviroment from a HTTP::Request
+
+SYNOPSIS
+        use CGI;
+        use HTTP::Request;
+        use HTTP::Request::AsCGI;
+    
+        my $request = HTTP::Request->new( GET => 'http://www.host.com/' );
+        my $stdout;
+    
+        {
+            my $c = HTTP::Request::AsCGI->new($request)->setup;
+            my $q = CGI->new;
+        
+            print $q->header,
+                  $q->start_html('Hello World'),
+                  $q->h1('Hello World'),
+                  $q->end_html;
+        
+            $stdout = $c->stdout;
+        
+            # enviroment and descriptors will automatically be restored 
+            # when $c is destructed.
+        }
+    
+        while ( my $line = $stdout->getline ) {
+            print $line;
+        }
+    
+DESCRIPTION
+    Provides a convinient way of setting up an CGI enviroment from a
+    HTTP::Request.
+
+METHODS
+    new ( $request [, key => value ] )
+        Contructor, first argument must be a instance of HTTP::Request
+        followed by optional pairs of environment key and value.
+
+    enviroment
+        Returns a hashref containing the environment that will be used in
+        setup. Changing the hashref after setup has been called will have no
+        effect.
+
+    setup
+        Setups the environment and descriptors.
+
+    restore
+        Restores the enviroment and descriptors. Can only be called after
+        setup.
+
+    request
+        Returns the request given to constructor.
+
+    response
+        Returns a HTTP::Response. Can only be called after restore.
+
+    stdin
+        Accessor for handle that will be used for STDIN, must be a real
+        seekable handle with an file descriptor. Defaults to a tempoary
+        IO::File instance.
+
+    stdout
+        Accessor for handle that will be used for STDOUT, must be a real
+        seekable handle with an file descriptor. Defaults to a tempoary
+        IO::File instance.
+
+    stderr
+        Accessor for handle that will be used for STDERR, must be a real
+        seekable handle with an file descriptor.
+
+SEE ALSO
+    examples directory in this distribution.
+    WWW::Mechanize::CGI
+    Test::WWW::Mechanize::CGI
+
+THANKS TO
+    Thomas L. Shinnick for his valuable win32 testing.
+
+AUTHOR
+    Christian Hansen, "ch at ngmedia.com"
+
+LICENSE
+    This library is free software. You can redistribute it and/or modify it
+    under the same terms as perl itself.
+

Added: branches/upstream/libhttp-request-ascgi-perl/current/examples/daemon.pl
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/examples/daemon.pl?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/examples/daemon.pl (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/examples/daemon.pl Mon Mar  3 20:45:33 2008
@@ -1,0 +1,74 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use CGI;
+use HTTP::Daemon;
+use HTTP::Request;
+use HTTP::Request::AsCGI;
+use HTTP::Response;
+use URI;
+
+$SIG{'PIPE'} = 'IGNORE';
+
+my $server = HTTP::Daemon->new( LocalPort => 3000, ReuseAddr => 1 )
+  or die( "Can't create daemon: $!" );
+
+print "Please contact me at: <URL:", $server->url, ">\n";
+
+while ( my $client = $server->accept ) {
+    
+    my %e = (
+        REMOTE_ADDR => $client->peerhost,
+        REMOTE_HOST => $client->peerhost,
+        REMOTE_PORT => $client->peerport
+    );
+
+    while ( my $request = $client->get_request ) {
+
+        unless ( $request->uri->host ) {
+            $request->uri( URI->new_abs( $request->uri, $server->url ) );
+        }
+
+        my $c = HTTP::Request::AsCGI->new( $request, %e )->setup;
+        my $q = CGI->new;
+
+        print $q->header( -charset => 'UTF-8' ),
+              $q->start_html( 
+                  -title    => 'Hello World',
+                  -encoding => 'UTF-8'
+              ),
+              $q->h1('Hello World'),
+              $q->start_form,
+              $q->table(
+                  $q->Tr( [
+                      $q->td( [ 'Name',  $q->textfield( -name => 'name'  ) ] ),
+                      $q->td( [ 'Email', $q->textfield( -name => 'email' ) ] ),
+                      $q->td( [ 'Phone', $q->textfield( -name => 'phone' ) ] ),
+                      $q->td( [ 'File',  $q->filefield( -name => 'file'  ) ] )
+                  ] )
+              ),
+              $q->submit,
+              $q->end_form,
+              $q->h2('Parameters'),
+              $q->Dump,
+              $q->h2('Enviroment'),
+              $q->table(
+                  $q->Tr( [
+                      map{ $q->td( [ $_, $ENV{$_} ] ) } sort keys %ENV
+                  ] )
+              ),
+              $q->end_html;
+
+        my $response = $c->restore->response;
+
+        # tell client to close socket to prevent blocking problems
+        # in this single threaded daemon.
+        $response->header( Connection => 'close' );
+
+        $client->send_response($response);
+    }
+
+    $client->close;
+}

Added: branches/upstream/libhttp-request-ascgi-perl/current/examples/synopsis.pl
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/examples/synopsis.pl?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/examples/synopsis.pl (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/examples/synopsis.pl Mon Mar  3 20:45:33 2008
@@ -1,0 +1,29 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use CGI;
+use HTTP::Request;
+use HTTP::Request::AsCGI;
+
+my $request = HTTP::Request->new( GET => 'http://www.host.com/' );
+my $stdout;
+
+{
+    my $c = HTTP::Request::AsCGI->new($request)->setup;
+    my $q = CGI->new;
+
+    print $q->header,
+          $q->start_html('Hello World'),
+          $q->h1('Hello World'),
+          $q->end_html;
+
+    $stdout = $c->stdout;
+
+    # enviroment and descriptors will automatically be restored when $c is destructed.
+}
+
+while ( my $line = $stdout->getline ) {
+    print $line;
+}

Added: branches/upstream/libhttp-request-ascgi-perl/current/lib/HTTP/Request/AsCGI.pm
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/lib/HTTP/Request/AsCGI.pm?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/lib/HTTP/Request/AsCGI.pm (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/lib/HTTP/Request/AsCGI.pm Mon Mar  3 20:45:33 2008
@@ -1,0 +1,382 @@
+package HTTP::Request::AsCGI;
+
+use strict;
+use warnings;
+use bytes;
+use base 'Class::Accessor::Fast';
+
+use Carp;
+use HTTP::Response;
+use IO::Handle;
+use IO::File;
+
+__PACKAGE__->mk_accessors(qw[ enviroment request stdin stdout stderr ]);
+
+our $VERSION = 0.5;
+
+sub new {
+    my $class   = shift;
+    my $request = shift;
+
+    unless ( @_ % 2 == 0 && eval { $request->isa('HTTP::Request') } ) {
+        croak(qq/usage: $class->new( \$request [, key => value] )/);
+    }
+
+    my $self = $class->SUPER::new( { restored => 0, setuped => 0 } );
+    $self->request($request);
+    $self->stdin( IO::File->new_tmpfile );
+    $self->stdout( IO::File->new_tmpfile );
+
+    my $host = $request->header('Host');
+    my $uri  = $request->uri->clone;
+    $uri->scheme('http')    unless $uri->scheme;
+    $uri->host('localhost') unless $uri->host;
+    $uri->port(80)          unless $uri->port;
+    $uri->host_port($host)  unless !$host || ( $host eq $uri->host_port );
+
+    $uri = $uri->canonical;
+
+    my $enviroment = {
+        GATEWAY_INTERFACE => 'CGI/1.1',
+        HTTP_HOST         => $uri->host_port,
+        HTTPS             => ( $uri->scheme eq 'https' ) ? 'ON' : 'OFF',  # not in RFC 3875
+        PATH_INFO         => $uri->path,
+        QUERY_STRING      => $uri->query || '',
+        SCRIPT_NAME       => '/',
+        SERVER_NAME       => $uri->host,
+        SERVER_PORT       => $uri->port,
+        SERVER_PROTOCOL   => $request->protocol || 'HTTP/1.1',
+        SERVER_SOFTWARE   => "HTTP-Request-AsCGI/$VERSION",
+        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
+        REQUEST_METHOD    => $request->method,
+        @_
+    };
+
+    foreach my $field ( $request->headers->header_field_names ) {
+
+        my $key = uc("HTTP_$field");
+        $key =~ tr/-/_/;
+        $key =~ s/^HTTP_// if $field =~ /^Content-(Length|Type)$/;
+
+        unless ( exists $enviroment->{$key} ) {
+            $enviroment->{$key} = $request->headers->header($field);
+        }
+    }
+
+    unless ( $enviroment->{SCRIPT_NAME} eq '/' && $enviroment->{PATH_INFO} ) {
+        $enviroment->{PATH_INFO} =~ s/^\Q$enviroment->{SCRIPT_NAME}\E/\//;
+        $enviroment->{PATH_INFO} =~ s/^\/+/\//;
+    }
+
+    $self->enviroment($enviroment);
+
+    return $self;
+}
+
+sub setup {
+    my $self = shift;
+
+    $self->{restore}->{enviroment} = {%ENV};
+
+    binmode( $self->stdin );
+
+    if ( $self->request->content_length ) {
+
+        syswrite( $self->stdin, $self->request->content )
+          or croak("Can't write request content to stdin handle: $!");
+
+        sysseek( $self->stdin, 0, SEEK_SET )
+          or croak("Can't seek stdin handle: $!");
+    }
+
+    open( $self->{restore}->{stdin}, '<&', STDIN->fileno )
+      or croak("Can't dup stdin: $!");
+
+    open( STDIN, '<&=', $self->stdin->fileno )
+      or croak("Can't open stdin: $!");
+
+    binmode( STDIN );
+
+    if ( $self->stdout ) {
+
+        open( $self->{restore}->{stdout}, '>&', STDOUT->fileno )
+          or croak("Can't dup stdout: $!");
+
+        open( STDOUT, '>&=', $self->stdout->fileno )
+          or croak("Can't open stdout: $!");
+
+        binmode( $self->stdout );
+        binmode( STDOUT);
+    }
+
+    if ( $self->stderr ) {
+
+        open( $self->{restore}->{stderr}, '>&', STDERR->fileno )
+          or croak("Can't dup stderr: $!");
+
+        open( STDERR, '>&=', $self->stderr->fileno )
+          or croak("Can't open stderr: $!");
+
+        binmode( $self->stderr );
+        binmode( STDERR );
+    }
+
+    {
+        no warnings 'uninitialized';
+        %ENV = %{ $self->enviroment };
+    }
+
+    if ( $INC{'CGI.pm'} ) {
+        CGI::initialize_globals();
+    }
+
+    $self->{setuped}++;
+
+    return $self;
+}
+
+sub response {
+    my ( $self, $callback ) = @_;
+
+    return undef unless $self->stdout;
+
+    seek( $self->stdout, 0, SEEK_SET )
+      or croak("Can't seek stdout handle: $!");
+
+    my $headers;
+    while ( my $line = $self->stdout->getline ) {
+        $headers .= $line;
+        last if $headers =~ /\x0d?\x0a\x0d?\x0a$/;
+    }
+    
+    unless ( defined $headers ) {
+        $headers = "HTTP/1.1 500 Internal Server Error\x0d\x0a";
+    }
+
+    unless ( $headers =~ /^HTTP/ ) {
+        $headers = "HTTP/1.1 200 OK\x0d\x0a" . $headers;
+    }
+
+    my $response = HTTP::Response->parse($headers);
+    $response->date( time() ) unless $response->date;
+
+    my $message = $response->message;
+    my $status  = $response->header('Status');
+
+    if ( $message && $message =~ /^(.+)\x0d$/ ) {
+        $response->message($1);
+    }
+
+    if ( $status && $status =~ /^(\d\d\d)\s?(.+)?$/ ) {
+
+        my $code    = $1;
+        my $message = $2 || HTTP::Status::status_message($code);
+
+        $response->code($code);
+        $response->message($message);
+    }
+    
+    my $length = ( stat( $self->stdout ) )[7] - tell( $self->stdout );
+
+    if ( $response->code == 500 && !$length ) {
+
+        $response->content( $response->error_as_HTML );
+        $response->content_type('text/html');
+
+        return $response;
+    }
+
+    if ($callback) {
+
+        my $handle = $self->stdout;
+
+        $response->content( sub {
+
+            if ( $handle->read( my $buffer, 4096 ) ) {
+                return $buffer;
+            }
+
+            return undef;
+        });
+    }
+    else {
+
+        my $length = 0;
+
+        while ( $self->stdout->read( my $buffer, 4096 ) ) {
+            $length += length($buffer);
+            $response->add_content($buffer);
+        }
+
+        if ( $length && !$response->content_length ) {
+            $response->content_length($length);
+        }
+    }
+
+    return $response;
+}
+
+sub restore {
+    my $self = shift;
+
+    {
+        no warnings 'uninitialized';
+        %ENV = %{ $self->{restore}->{enviroment} };
+    }
+
+    open( STDIN, '<&', $self->{restore}->{stdin} )
+      or croak("Can't restore stdin: $!");
+
+    sysseek( $self->stdin, 0, SEEK_SET )
+      or croak("Can't seek stdin: $!");
+
+    if ( $self->{restore}->{stdout} ) {
+
+        STDOUT->flush
+          or croak("Can't flush stdout: $!");
+
+        open( STDOUT, '>&', $self->{restore}->{stdout} )
+          or croak("Can't restore stdout: $!");
+
+        sysseek( $self->stdout, 0, SEEK_SET )
+          or croak("Can't seek stdout: $!");
+    }
+
+    if ( $self->{restore}->{stderr} ) {
+
+        STDERR->flush
+          or croak("Can't flush stderr: $!");
+
+        open( STDERR, '>&', $self->{restore}->{stderr} )
+          or croak("Can't restore stderr: $!");
+
+        sysseek( $self->stderr, 0, SEEK_SET )
+          or croak("Can't seek stderr: $!");
+    }
+
+    $self->{restored}++;
+
+    return $self;
+}
+
+sub DESTROY {
+    my $self = shift;
+    $self->restore if $self->{setuped} && !$self->{restored};
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+HTTP::Request::AsCGI - Setup a CGI enviroment from a HTTP::Request
+
+=head1 SYNOPSIS
+
+    use CGI;
+    use HTTP::Request;
+    use HTTP::Request::AsCGI;
+    
+    my $request = HTTP::Request->new( GET => 'http://www.host.com/' );
+    my $stdout;
+    
+    {
+        my $c = HTTP::Request::AsCGI->new($request)->setup;
+        my $q = CGI->new;
+        
+        print $q->header,
+              $q->start_html('Hello World'),
+              $q->h1('Hello World'),
+              $q->end_html;
+        
+        $stdout = $c->stdout;
+        
+        # enviroment and descriptors will automatically be restored 
+        # when $c is destructed.
+    }
+    
+    while ( my $line = $stdout->getline ) {
+        print $line;
+    }
+    
+=head1 DESCRIPTION
+
+Provides a convinient way of setting up an CGI enviroment from a HTTP::Request.
+
+=head1 METHODS
+
+=over 4 
+
+=item new ( $request [, key => value ] )
+
+Contructor, first argument must be a instance of HTTP::Request
+followed by optional pairs of environment key and value.
+
+=item enviroment
+
+Returns a hashref containing the environment that will be used in setup. 
+Changing the hashref after setup has been called will have no effect.
+
+=item setup
+
+Setups the environment and descriptors.
+
+=item restore
+
+Restores the enviroment and descriptors. Can only be called after setup.
+
+=item request
+
+Returns the request given to constructor.
+
+=item response
+
+Returns a HTTP::Response. Can only be called after restore.
+
+=item stdin
+
+Accessor for handle that will be used for STDIN, must be a real seekable
+handle with an file descriptor. Defaults to a tempoary IO::File instance.
+
+=item stdout
+
+Accessor for handle that will be used for STDOUT, must be a real seekable
+handle with an file descriptor. Defaults to a tempoary IO::File instance.
+
+=item stderr
+
+Accessor for handle that will be used for STDERR, must be a real seekable
+handle with an file descriptor.
+
+=back
+
+=head1 SEE ALSO
+
+=over 4
+
+=item examples directory in this distribution.
+
+=item L<WWW::Mechanize::CGI>
+
+=item L<Test::WWW::Mechanize::CGI>
+
+=back
+
+=head1 THANKS TO
+
+Thomas L. Shinnick for his valuable win32 testing.
+
+=head1 AUTHOR
+
+Christian Hansen, C<ch at ngmedia.com>
+
+=head1 LICENSE
+
+This library is free software. You can redistribute it and/or modify 
+it under the same terms as perl itself.
+
+=cut

Added: branches/upstream/libhttp-request-ascgi-perl/current/t/01use.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/t/01use.t?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/t/01use.t (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/t/01use.t Mon Mar  3 20:45:33 2008
@@ -1,0 +1,8 @@
+#!perl
+
+use Test::More 'no_plan';
+
+use strict;
+use warnings;
+
+use_ok 'HTTP::Request::AsCGI';

Added: branches/upstream/libhttp-request-ascgi-perl/current/t/04io.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/t/04io.t?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/t/04io.t (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/t/04io.t Mon Mar  3 20:45:33 2008
@@ -1,0 +1,28 @@
+#!perl
+
+use Test::More tests => 3;
+
+use strict;
+use warnings;
+
+use IO::File;
+use HTTP::Request;
+use HTTP::Request::AsCGI;
+
+my $r = HTTP::Request->new( POST => 'http://www.host.com/');
+$r->content('STDIN');
+$r->content_length(5);
+$r->content_type('text/plain');
+
+my $c = HTTP::Request::AsCGI->new($r);
+$c->stderr(IO::File->new_tmpfile);
+$c->setup;
+
+print STDOUT 'STDOUT';
+print STDERR 'STDERR';
+
+$c->restore;
+
+is( $c->stdin->getline,  'STDIN',  'STDIN' );
+is( $c->stdout->getline, 'STDOUT', 'STDOUT' );
+is( $c->stderr->getline, 'STDERR', 'STDERR' );

Added: branches/upstream/libhttp-request-ascgi-perl/current/t/05env.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/t/05env.t?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/t/05env.t (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/t/05env.t Mon Mar  3 20:45:33 2008
@@ -1,0 +1,30 @@
+#!perl
+
+use Test::More tests => 10;
+
+use strict;
+use warnings;
+
+use HTTP::Request;
+use HTTP::Request::AsCGI;
+
+my $r = HTTP::Request->new( GET => 'http://www.host.com/cgi-bin/script.cgi/my/path/?a=1&b=2', [ 'X-Test' => 'Test' ] );
+my %e = ( SCRIPT_NAME => '/cgi-bin/script.cgi' );
+my $c = HTTP::Request::AsCGI->new( $r, %e );
+$c->stdout(undef);
+
+$c->setup;
+
+is( $ENV{GATEWAY_INTERFACE}, 'CGI/1.1', 'GATEWAY_INTERFACE' );
+is( $ENV{HTTP_HOST}, 'www.host.com:80', 'HTTP_HOST' );
+is( $ENV{HTTP_X_TEST}, 'Test', 'HTTP_X_TEST' );
+is( $ENV{PATH_INFO}, '/my/path/', 'PATH_INFO' );
+is( $ENV{QUERY_STRING}, 'a=1&b=2', 'QUERY_STRING' );
+is( $ENV{SCRIPT_NAME}, '/cgi-bin/script.cgi', 'SCRIPT_NAME' );
+is( $ENV{REQUEST_METHOD}, 'GET', 'REQUEST_METHOD' );
+is( $ENV{SERVER_NAME}, 'www.host.com', 'SERVER_NAME' );
+is( $ENV{SERVER_PORT}, '80', 'SERVER_PORT' );
+
+$c->restore;
+
+is( $ENV{GATEWAY_INTERFACE}, undef, 'No CGI env after restore' );

Added: branches/upstream/libhttp-request-ascgi-perl/current/t/06response.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/t/06response.t?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/t/06response.t (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/t/06response.t Mon Mar  3 20:45:33 2008
@@ -1,0 +1,39 @@
+#!perl
+
+use Test::More tests => 9;
+
+use strict;
+use warnings;
+
+use IO::File;
+use HTTP::Request;
+use HTTP::Request::AsCGI;
+
+my $response;
+
+{
+    my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
+    my $c = HTTP::Request::AsCGI->new($r);
+
+    $c->setup;
+    
+    print "Content-Type: text/plain\n";
+    print "Status: 200 Yay\n";
+    print "Date: Thu, 19 Jan 2006 14:08:18 GMT\n";
+    print "X-Field: 1\n";
+    print "X-Field: 2\n";
+    print "\n";
+    print "Hello!";
+
+    $response = $c->restore->response;
+}
+
+isa_ok( $response, 'HTTP::Response' );
+is( $response->code, 200, 'Response Code' );
+is( $response->message, 'Yay', 'Response Message' );
+is( $response->protocol, 'HTTP/1.1', 'Response Protocol' );
+is( $response->content, 'Hello!', 'Response Content' );
+is( $response->content_length, 6, 'Response Content-Length' );
+is( $response->content_type, 'text/plain', 'Response Content-Type' );
+is( $response->header('Date'), 'Thu, 19 Jan 2006 14:08:18 GMT', 'Response Date' );
+is_deeply( [ $response->header('X-Field') ], [ 1, 2 ], 'Response Header X-Field' );

Added: branches/upstream/libhttp-request-ascgi-perl/current/t/07forking.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/t/07forking.t?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/t/07forking.t (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/t/07forking.t Mon Mar  3 20:45:33 2008
@@ -1,0 +1,59 @@
+#!perl
+
+use strict;
+use warnings;
+
+use Config;
+use IO::File;
+use HTTP::Request;
+use HTTP::Request::AsCGI;
+use Test::More;
+
+unless ( $Config{d_fork} ) {
+    plan skip_all => 'This test requires a plattform that supports fork()';
+}
+
+plan tests => 8;
+
+my $response;
+
+{
+    my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
+    my $c = HTTP::Request::AsCGI->new($r);
+
+    my $kid = fork();
+
+    unless ( defined $kid ) {
+        die("Can't fork() kid: $!");
+    }
+
+    unless ( $kid ) {
+
+        $c->setup;
+
+        print "HTTP/1.0 200 OK\n";
+        print "Content-Type: text/plain\n";
+        print "Status: 200\n";
+        print "X-Field: 1\n";
+        print "X-Field: 2\n";
+        print "\n";
+        print "Hello!";
+
+        $c->restore;
+
+        exit(0);
+    }
+
+    waitpid( $kid, 0 );
+
+    $response = $c->response;
+}
+
+isa_ok( $response, 'HTTP::Response' );
+is( $response->code, 200, 'Response Code' );
+is( $response->message, 'OK', 'Response Message' );
+is( $response->protocol, 'HTTP/1.0', 'Response Protocol' );
+is( $response->content, 'Hello!', 'Response Content' );
+is( $response->content_length, 6, 'Response Content-Length' );
+is( $response->content_type, 'text/plain', 'Response Content-Type' );
+is_deeply( [ $response->header('X-Field') ], [ 1, 2 ], 'Response Header X-Field' );

Added: branches/upstream/libhttp-request-ascgi-perl/current/t/08error.t
URL: http://svn.debian.org/wsvn/branches/upstream/libhttp-request-ascgi-perl/current/t/08error.t?rev=16395&op=file
==============================================================================
--- branches/upstream/libhttp-request-ascgi-perl/current/t/08error.t (added)
+++ branches/upstream/libhttp-request-ascgi-perl/current/t/08error.t Mon Mar  3 20:45:33 2008
@@ -1,0 +1,49 @@
+#!perl
+
+use Test::More tests => 12;
+
+use strict;
+use warnings;
+
+use IO::File;
+use HTTP::Request;
+use HTTP::Request::AsCGI;
+
+my $response;
+
+{
+    my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
+    my $c = HTTP::Request::AsCGI->new($r);
+
+    $c->setup;
+
+    $response = $c->restore->response;
+}
+
+isa_ok( $response, 'HTTP::Response' );
+is( $response->code, 500, 'Response Code' );
+is( $response->message, 'Internal Server Error', 'Response Message' );
+is( $response->protocol, 'HTTP/1.1', 'Response Protocol' );
+is( $response->content_type, 'text/html', 'Response Content-Type' );
+ok( length($response->content) > 0, 'Response Content' );
+
+{
+    my $r = HTTP::Request->new( GET => 'http://www.host.com/' );
+    my $c = HTTP::Request::AsCGI->new($r);
+
+    $c->setup;
+    
+    print "Content-Type: text/plain\n";
+    print "Status: 500 Borked\n";
+    print "\n";
+    print "Borked!";
+
+    $response = $c->restore->response;
+}
+
+isa_ok( $response, 'HTTP::Response' );
+is( $response->code, 500, 'Response Code' );
+is( $response->message, 'Borked', 'Response Message' );
+is( $response->protocol, 'HTTP/1.1', 'Response Protocol' );
+is( $response->content_type, 'text/plain', 'Response Content-Type' );
+is( $response->content, 'Borked!', 'Response Content' );




More information about the Pkg-perl-cvs-commits mailing list