.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Apache2::Request 3pm" .TH Apache2::Request 3pm "2023-02-07" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Apache2::Request \- Methods for dealing with client request data .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 4 \& use Apache2::Request; \& $req = Apache2::Request\->new($r); \& @foo = $req\->param("foo"); \& $bar = $req\->args("bar"); .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" The Apache2::Request module provides methods for parsing \s-1GET\s0 and \s-1POST\s0 parameters encoded with either \fIapplication/x\-www\-form\-urlencoded\fR or \fImultipart/form\-data\fR. Although Apache2::Request provides a few new APIs for accessing the parsed data, it remains largely backwards-compatible with the original 1.X \s-1API.\s0 See the \&\*(L"\s-1PORTING\s0 from 1.X\*(R" section below for a list of known issues. .PP This manpage documents the Apache2::Request package. .SH "Apache2::Request" .IX Header "Apache2::Request" The interface is designed to mimic the \s-1CGI\s0.pm routines for parsing query parameters. The main differences are .IP "\(bu" 4 \&\f(CW\*(C`Apache2::Request::new\*(C'\fR takes an environment-specific object \f(CW$r\fR as (second) argument. Newer versions of \s-1CGI\s0.pm also accept this syntax within modperl. .IP "\(bu" 4 The query parameters are stored in APR::Table derived objects, and are therefore retrieved from the table by using case-insensitive keys. .IP "\(bu" 4 The query string is always parsed immediately, even for \s-1POST\s0 requests. .SS "new" .IX Subsection "new" .Vb 1 \& Apache2::Request\->new($r, %args) .Ve .PP Creates a new Apache2::Request object. .PP .Vb 1 \& my $req = Apache2::Request\->new($r, POST_MAX => "1M"); .Ve .PP With mod_perl2, the environment object \f(CW$r\fR must be an Apache2::RequestRec object. In that case, all methods from Apache2::RequestRec are inherited. In the (default) \s-1CGI\s0 environment, \f(CW$r\fR must be an APR::Pool object. .PP The following args are optional: .IP "\(bu" 4 \&\f(CW\*(C`POST_MAX\*(C'\fR, \f(CW\*(C`MAX_BODY\*(C'\fR .Sp Limit the size of \s-1POST\s0 data (in bytes). .IP "\(bu" 4 \&\f(CW\*(C`DISABLE_UPLOADS\*(C'\fR .Sp Disable file uploads. .IP "\(bu" 4 \&\f(CW\*(C`TEMP_DIR\*(C'\fR .Sp Sets the directory where upload files are spooled. On a *nix\-like that supports \fI\f(BIlink\fI\|(2)\fR, the \s-1TEMP_DIR\s0 should be located on the same file system as the final destination file: .Sp .Vb 4 \& use Apache2::Upload; \& my $req = Apache2::Request\->new($r, TEMP_DIR => "/home/httpd/tmp"); \& my $upload = $req\->upload(\*(Aqfile\*(Aq); \& $upload\->link("/home/user/myfile"); .Ve .Sp For more details on \f(CW\*(C`link\*(C'\fR, see Apache2::Upload. .IP "\(bu" 4 \&\f(CW\*(C`HOOK_DATA\*(C'\fR .Sp Extra configuration info passed as the fourth argument to an upload hook. See the description for the next item, \&\f(CW\*(C`UPLOAD_HOOK\*(C'\fR. .IP "\(bu" 4 \&\f(CW\*(C`UPLOAD_HOOK\*(C'\fR .Sp Sets up a callback to run whenever file upload data is read. This can be used to provide an upload progress meter during file uploads. Apache will automatically continue writing the original data to \&\f(CW$upload\fR\->fh after the hook exits. .Sp .Vb 4 \& my $transparent_hook = sub { \& my ($upload, $data, $data_len, $hook_data) = @_; \& warn "$hook_data: got $data_len bytes for " . $upload\->name; \& }; \& \& my $req = Apache2::Request\->new($r, \& HOOK_DATA => "Note", \& UPLOAD_HOOK => $transparent_hook, \& ); .Ve .SS "instance" .IX Subsection "instance" .Vb 1 \& Apache2::Request\->instance($r) .Ve .PP The default (and only) behavior of \fIApache2::Request\fR is to intelligently cache \fB\s-1POST\s0\fR data for the duration of the request. Thus there is no longer the need for a separate \f(CW\*(C`instance()\*(C'\fR method as existed in \fIApache2::Request\fR for Apache 1.3 \- all \fB\s-1POST\s0\fR data is always available from each and every \&\fIApache2::Request\fR object created during the request's lifetime. .PP However an \f(CW\*(C`instance()\*(C'\fR method is aliased to \f(CW\*(C`new()\*(C'\fR in this release to ease the pain of porting from 1.X to 2.X. .SS "param" .IX Subsection "param" .Vb 2 \& $req\->param() \& $req\->param($name) .Ve .PP Get the request parameters (using case-insensitive keys) by mimicing the \s-1OO\s0 interface of \f(CW\*(C`CGI::param\*(C'\fR. .PP .Vb 1 \& # similar to CGI.pm \& \& my $foo_value = $req\->param(\*(Aqfoo\*(Aq); \& my @foo_values = $req\->param(\*(Aqfoo\*(Aq); \& my @param_names = $req\->param; \& \& # the following differ slightly from CGI.pm \& \& # returns ref to APR::Request::Param::Table object representing \& # all (args + body) params \& my $table = $req\->param; \& @table_keys = keys %$table; .Ve .PP In list context, or when invoked with no arguments as \&\f(CW\*(C`$req\->param()\*(C'\fR, \f(CW\*(C`param\*(C'\fR induces libapreq2 to read and parse all remaining data in the request body. However, \f(CW\*(C`scalar $req\->param("foo")\*(C'\fR is lazy: libapreq2 will only read and parse more data if .PP .Vb 2 \& 1) no "foo" param appears in the query string arguments, AND \& 2) no "foo" param appears in the previously parsed POST data. .Ve .PP In this circumstance libapreq2 will read and parse additional blocks of the incoming request body until either .PP .Vb 2 \& 1) it has found the the "foo" param, or \& 2) parsing is completed. .Ve .PP Observe that \f(CW\*(C`scalar $req\->param("foo")\*(C'\fR will not raise an exception if it can locate \*(L"foo\*(R" in the existing body or args tables, even if the query-string parser or the body parser has failed. In all other circumstances \f(CW\*(C`param\*(C'\fR will throw an Apache2::Request::Error object into $@ should either parser fail. .PP .Vb 2 \& $req\->args_status(1); # set error state for query\-string parser \& ok $req\->param_status == 1; \& \& $foo = $req\->param("foo"); \& ok $foo == 1; \& eval { @foo = $req\->param("foo") }; \& ok $@\->isa("Apache2::Request::Error"); \& undef $@; \& eval { my $not_found = $req\->param("non\-existent\-param") }; \& ok $@\->isa("Apache2::Request::Error"); \& \& $req\->args_status(0); # reset query\-string parser state to "success" .Ve .PP Note: modifications to the \f(CW\*(C`scalar $req\->param()\*(C'\fR table only affect the returned table object (the underlying C apr_table_t is \&\fIgenerated\fR from the parse data by \fBapreq_params()\fR). Modifications do not affect the actual request data, and will not be seen by other libapreq2 applications. .SS "parms, params" .IX Subsection "parms, params" The functionality of these functions is assumed by \f(CW\*(C`param\*(C'\fR, so they are no longer necessary. Aliases to \f(CW\*(C`param\*(C'\fR are provided in this release for backwards compatibility, however they are deprecated and may be removed from a future release. .SS "body" .IX Subsection "body" .Vb 2 \& $req\->body() \& $req\->body($name) .Ve .PP Returns an \fIAPR::Request::Param::Table\fR object containing the \s-1POST\s0 data parameters of the \fIApache2::Request\fR object. .PP .Vb 1 \& my $body = $req\->body; .Ve .PP An optional name parameter can be passed to return the \s-1POST\s0 data parameter associated with the given name: .PP .Vb 1 \& my $foo_body = $req\->body("foo"); .Ve .PP More generally, \f(CW\*(C`body()\*(C'\fR follows the same pattern as \f(CW\*(C`param()\*(C'\fR with respect to its return values and argument list. The main difference is that modifications to the \f(CW\*(C`scalar $req\->body()\*(C'\fR table affect the underlying apr_table_t attribute in apreq_request_t, so their impact will be noticed by all libapreq2 applications during this request. .SS "upload" .IX Subsection "upload" .Vb 2 \& $req\->upload() \& $req\->upload($name) .Ve .PP Requires \f(CW\*(C`Apache2::Upload\*(C'\fR. With no arguments, this method returns an \fIAPR::Request::Param::Table\fR object in scalar context, or the names of all \fIApache2::Upload\fR objects in list context. .PP An optional name parameter can be passed to return the \fIApache2::Upload\fR object associated with the given name: .PP .Vb 1 \& my $upload = $req\->upload($name); .Ve .PP More generally, \f(CW\*(C`upload()\*(C'\fR follows the same pattern as \f(CW\*(C`param()\*(C'\fR with respect to its return values and argument list. The main difference is that its returned values are Apache2::Upload object refs, not simple scalars. .PP Note: modifications to the \f(CW\*(C`scalar $req\->upload()\*(C'\fR table only affect the returned table object (the underlying C apr_table_t is \&\fIgenerated\fR by \fBapreq_uploads()\fR). They do not affect the actual request data, and will not be seen by other libapreq2 applications. .SS "args_status" .IX Subsection "args_status" .Vb 1 \& $req\->args_status() .Ve .PP Get the \fI\s-1APR\s0\fR status code of the query-string parser. \&\s-1APR_SUCCESS\s0 on success, error otherwise. .SS "body_status" .IX Subsection "body_status" .Vb 1 \& $req\->body_status() .Ve .PP Get the current \fI\s-1APR\s0\fR status code of the parsed \s-1POST\s0 data. \&\s-1APR_SUCCESS\s0 when parser has completed, \s-1APR_INCOMPLETE\s0 if parser has more data to parse, \s-1APR_EINIT\s0 if no post data has been parsed, error otherwise. .SS "param_status" .IX Subsection "param_status" .Vb 1 \& $req\->param_status() .Ve .PP In scalar context, this returns \f(CW\*(C`args_status\*(C'\fR if there was an error during the query-string parse, otherwise this returns \&\f(CW\*(C`body_status\*(C'\fR, ie .PP .Vb 1 \& $req\->args_status || $req\->body_status .Ve .PP In list context \f(CW\*(C`param_status\*(C'\fR returns the list \&\f(CW\*(C`(args_status, body_status)\*(C'\fR. .SS "parse" .IX Subsection "parse" .Vb 1 \& $req\->parse() .Ve .PP Forces the request to be parsed immediately. In void context, this will throw an APR::Request::Error should the either the query-string or body parser fail. In all other contexts it will return the two parsers' combined \fI\s-1APR\s0\fR status code .PP .Vb 1 \& $req\->body_status || $req\->args_status .Ve .PP However \f(CW\*(C`parse\*(C'\fR should be avoided in most normal situations. For example, in a mod_perl content handler it is more efficient to write .PP .Vb 5 \& sub handler { \& my $r = shift; \& my $req = Apache2::Request\->new($r); \& $r\->discard_request_body; # efficiently parses the request body \& my $parser_status = $req\->body_status; \& \& #... \& } .Ve .PP Calling \f(CW\*(C`$r\->discard_request_body\*(C'\fR outside the content handler is generally a mistake, so use \f(CW\*(C`$req\->parse\*(C'\fR there, but \&\fBonly as a last resort\fR. The Apache2::Request \s-1API\s0 is \fBdesigned\fR around a lazy-parsing scheme, so calling \f(CW\*(C`parse\*(C'\fR should not affect the behavior of any other methods. .SH "SUBCLASSING Apache2::Request" .IX Header "SUBCLASSING Apache2::Request" If the instances of your subclass are hash references then you can actually inherit from Apache2::Request as long as the Apache2::Request object is stored in an attribute called \*(L"r\*(R" or \*(L"_r\*(R". (The Apache2::Request class effectively does the delegation for you automagically, as long as it knows where to find the Apache2::Request object to delegate to.) For example: .PP .Vb 7 \& package MySubClass; \& use Apache2::Request; \& our @ISA = qw(Apache2::Request); \& sub new { \& my($class, @args) = @_; \& return bless { r => Apache2::Request\->new(@args) }, $class; \& } .Ve .SH "PORTING from 1.X" .IX Header "PORTING from 1.X" This is the complete list of changes to existing methods from Apache2::Request 1.X. These issues need to be addressed when porting 1.X apps to the new 2.X \s-1API.\s0 .IP "\(bu" 4 Apache2::Upload is now a separate module. Applications requiring the upload \s-1API\s0 must \f(CW\*(C`use Apache2::Upload\*(C'\fR in 2.X. This is easily addressed by preloading the modules during server startup. .IP "\(bu" 4 You can no longer add (or set or delete) parameters in the \f(CW\*(C`scalar $req\->param\*(C'\fR, \f(CW\*(C`scalar $req\->args\*(C'\fR or \f(CW\*(C`scalar $req\->body\*(C'\fR tables. Nor can you add (or set or delete) cookies in the \f(CW\*(C`scalar $req\->jar\*(C'\fR table. .IP "\(bu" 4 \&\f(CW\*(C`instance()\*(C'\fR is now identical to \f(CW\*(C`new()\*(C'\fR, and is now deprecated. It may be removed from a future 2.X release. .IP "\(bu" 4 \&\f(CW\*(C`param\*(C'\fR includes the functionality of \f(CW\*(C`parms()\*(C'\fR and \f(CW\*(C`params()\*(C'\fR, so they are now deprecated and may be removed from a future 2.X release. .IP "\(bu" 4 \&\f(CW\*(C`param\*(C'\fR called in a list context no longer returns a unique list of paramaters. The returned list contains multiple instances of the parameter name for multivalued fields. .SH "SEE ALSO" .IX Header "SEE ALSO" APR::Request::Param, APR::Request::Error, Apache2::Upload, Apache2::Cookie, \fBAPR::Table\fR\|(3). .SH "COPYRIGHT" .IX Header "COPYRIGHT" .Vb 6 \& Licensed to the Apache Software Foundation (ASF) under one or more \& contributor license agreements. See the NOTICE file distributed with \& this work for additional information regarding copyright ownership. \& The ASF licenses this file to You under the Apache License, Version 2.0 \& (the "License"); you may not use this file except in compliance with \& the License. You may obtain a copy of the License at \& \& http://www.apache.org/licenses/LICENSE\-2.0 \& \& Unless required by applicable law or agreed to in writing, software \& distributed under the License is distributed on an "AS IS" BASIS, \& WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \& See the License for the specific language governing permissions and \& limitations under the License. .Ve