The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Dendral::HTTP::Request - Perl interface for Apache request variables

SYNOPSIS

# Mod_perl handler
use Dendral::HTTP::Request;

sub handler
{
    my $r = shift;
    my $req = new Dendral::HTTP::Request($r, POST_MAX      => -1,
                                             MAX_FILES     => -1,
                                             MAX_FILE_SIZE => -1,
                                             TMP_DIR       => '/tmp');
    # Retrieve parameter, sigle value
    my $foo = $req -> param('foo');

    # Retrieve array or params
    my @foo = $req -> param('foo');

    # Retrieve all given parameters
    my $all_params_hashref = $req -> params();

    # Retrieve cookie by name
    my $bar_cookie = $req -> cookie('bar');

    # Retrieve all given cookies
    my $all_cookies_hashref = $req -> cookies();

    # Retrieve header value
    my $accept = $req -> header('Accept');

    # Retrieve all given headers
    my $all_headers_hashref = $req -> headers();

    # Get other request parameters such as host, method, query string, etc
    my $req_info = {
                     host         => $req -> host,
                     method       => $req -> method,
                     request_time => $req -> request_time,
                     the_request  => $req -> the_request,
                     protocol     => $req -> protocol,
                     unparsed_uri => $req -> unparsed_uri,
                     uri          => $req -> uri,
                     filename     => $req -> filename,
                     path_info    => $req -> path_info,
                     args         => $req -> args,
                     remote_ip    => $req -> remote_ip,
                     local_ip     => $req -> local_ip,
                     port         => $req -> port
                   };

}

DESCRIPTION

Dendral::HTTP::Request is a part of Dendral - fast, reliable and lightweight MVC framework.

This module is very similar to well-known Apache::Request.

METHODS

new - Constructor

Create a new Dendral::HTTP::Request object with an Apache request_rec object:

my $req = new Dendral::HTTP::Request($r, POST_MAX      => -1,
                                         MAX_FILES     => -1,
                                         MAX_FILE_SIZE => -1,
                                         TMP_DIR       => '/tmp');

MAX_POST, POST_MAX - Limit of POST request size, bytes; -1 means no limit, 0 - POST method is disabled.

TMP_DIR, TEMP_DIR, TEMPFILE_DIR - Directory where upload files are spooled, default is /tmp.

MAX_FILES - Limit of number of files; -1 means no limit, 0 - uploading of files is disabled.

MAX_FILE_SIZE - Uploaded file size limit, bytes; -1 means no limit, 0 - uploading of files is disabled.

DIE_ON_ERRORS - If set, module should die if any error occured.

param - Get request parameter(s)

my $foo = $req -> param('foo');
my @foo = $req -> param('foo');
my $all_params_hashref = $req -> param();

params - Get all request parameters

my $all_params_hashref = $req -> params();
my $bar_cookie = $req -> cookie('bar');
my @bar_cookie = $req -> cookie('bar');
my $all_cookies_hashref = $req -> cookie();

cookies - Get all request cookies

my $all_cookies_hashref = $req -> cookies();

header - Get request header(s)

my $accept_header = $req -> header('Accept');
my @accept_header = $req -> header('Accept');
my $all_headers_hashref = $req -> header();

headers - Get all request headers

my $all_headers_hashref = $req -> headers();

port - Get server port

my $port = $req -> port();

host - Get server host, as set by full URI or Host

my $host = $req -> host();

protocol - Get protocol, as given to Apache, or HTTP/0.9

my $protocol = $req -> protocol();

method - Get request method: GET, HEAD, POST, etc.

my $method = $req -> method();

args - Get query string arguments

my $query_string_args = $req -> args();

path_info - Path part

my $path_info = $req -> path_info();

filename - filename if found, otherwise undef

my $filename = $req -> filename();

uri - the path portion of the URI

my $uri = $req -> uri();

unparsed_uri - The URI without any parsing performed

my $unparsed_uri = $req -> unparsed_uri();

the_request - First line of request

my $the_request = $req -> the_request();

request_time - Time, when the request started

my $request_time = $req -> request_time();

local_ip - Get local (server) IP address

my $local_ip = $req -> local_ip();

remote_ip - Get remote IP address

my $remote_ip = $req -> remote_ip();

raw - Get raw request data

my $raw_post_data = $req -> raw();

file - Get uploaded file(s) info by input name.

my $file = $req -> file('upload_file');
my @files = $req -> file();

my $file_name      = $file -> {'file_name'};
my $tmp_name       = $file -> {'tmp_name'};
my $full_filename  = $file -> {'full_filename'};
my $filesize       = $file -> {'filesize'};
my $content_type   = $file -> {'content_type'};
my $content_tr_enc = $file -> {'content_transfer_encoding'};

EXAMPLES

See file examples/Mytest.pm

AUTHOR

Andrei V. Shetuhin (reki@reki.ru)

SEE ALSO

perl(1), Apache(3), Apache::Request(3)

WEBSITE

http://dendral.havoc.ru/en/ - in English

http://dendral.havoc.ru/ - for Russian speakers

LICENSE

Copyright (c) 2005 - 2011 CAS Dev Team

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
   notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
   notice, this list of conditions and the following disclaimer in the
   documentation and/or other materials provided with the distribution.
4. Neither the name of the CAS Dev. Team nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.