NAME

HTTP::Request::AsCGI - Setup a Common Gateway Interface environment 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;

    # environment and descriptors is automatically restored
    # when $c is destructed.
}

while ( my $line = $stdout->getline ) {
    print $line;
}

DESCRIPTION

Provides a convinient way of setting up an CGI environment from a HTTP::Request.

METHODS

  • new

    Constructor, this method takes a hash of parameters. The following parameters are valid:

    • request

      request => HTTP::Request->new( GET => 'http://www.host.com/' )
    • stdin

      A filehandle to be used as standard input, defaults to a temporary filehandle. If stdin is undef, standard input will be left as is.

      stdin => IO::File->new_tmpfile
      stdin => IO::String->new
      stdin => $fh
      stdin => undef
    • stdout

      A filehandle to be used as standard output, defaults to a temporary filehandle. If stdout is undef, standard output will be left as is.

      stdout => IO::File->new_tmpfile
      stdout => IO::String->new
      stdout => $fh
      stdout => undef
    • stderr

      A filehandle to be used as standard error, defaults to undef. If stderr is undef, standard error will be left as is.

      stderr => IO::File->new_tmpfile
      stderr => IO::String->new
      stderr => $fh
      stderr => undef
    • environment

      A HASH of additional environment variables to be used in CGI. HTTP::Request::AsCGI doesn't autmatically merge %ENV, it has to be explicitly given if that is desired. Environment variables given in this HASH isn't overridden by HTTP::Request::AsCGI.

      environment => \%ENV
      environment => { PATH => '/bin:/usr/bin', SERVER_SOFTWARE => 'Apache/1.3' }

      Following standard meta-variables (in addition to protocol-specific) is setup:

      AUTH_TYPE
      CONTENT_LENGTH
      CONTENT_TYPE
      GATEWAY_INTERFACE
      PATH_INFO
      SCRIPT_NAME
      SERVER_NAME
      SERVER_PORT
      SERVER_PROTOCOL
      SERVER_SOFTWARE
      REMOTE_ADDR
      REMOTE_HOST
      REMOTE_USER
      REQUEST_METHOD
      QUERY_STRING

      Following non-standard but common meta-variables is setup:

      HTTPS
      REMOTE_PORT
      REQUEST_URI

      Following meta-variables is not setup but must be provided in CGI:

      PATH_TRANSLATED

      Following meta-variables is not setup but common in CGI:

      DOCUMENT_ROOT
      SCRIPT_FILENAME
      SERVER_ROOT
    • dup

      Boolean to indicate whether to dup standard filehandle or to assign the typeglob representing the standard filehandle. Defaults to true.

      dup => 0
      dup => 1
    • restore

      Boolean to indicate whether or not to restore environment variables and standard filehandles. Defaults to true.

      restore => 0
      restore => 1

      If true standard filehandles and environment variables will be saved duiring setup for later use in restore.

    • rewind

      Boolean to indicate whether or not to rewind standard filehandles. Defaults to true.

      rewind => 0
      rewind => 1
    • content

      Boolean to indicate whether or not to request content should be written to stdin filehandle when setup is invoked. Defaults to true.

      content => 0
      content => 1
  • setup

    Attempts to setup standard filehandles and environment variables.

  • restore

    Attempts to restore standard filehandles and environment variables.

  • response

    Attempts to parse stdout filehandle into a HTTP::Response.

  • request

    Accessor for HTTP::Request that was given to constructor.

  • environment

    Accessor for environment variables to be used in setup.

  • stdin

    Accessor/Mutator for standard input filehandle.

  • stdout

    Accessor/Mutator for standard output filehandle.

  • stderr

    Accessor/Mutator for standard error filehandle.

DEPRECATED

XXX Constructor

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@ngmedia.com

LICENSE

This library is free software. You can redistribute it and/or modify it under the same terms as perl itself.