📄 apache2::request.3
字号:
\& $req\->param($name).Ve.PPGet the request parameters (using case-insensitive keys) bymimicing 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.PPIn 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 readand parse all remaining data in the request body.However, \f(CW\*(C`scalar $req\->param("foo")\*(C'\fR is lazy: libapreq2will 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.PPIn this circumstance libapreq2 will read and parse additionalblocks of the incoming request body until either.PP.Vb 2\& 1) it has found the the "foo" param, or\& 2) parsing is completed..Ve.PPObserve that \f(CW\*(C`scalar $req\->param("foo")\*(C'\fR will not raisean exception if it can locate \*(L"foo\*(R" in the existing body orargs tables, even if the query-string parser or the body parserhas failed. In all other circumstances \f(CW\*(C`param\*(C'\fR will throw anApache2::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.PPNote: modifications to the \f(CW\*(C`scalar $req\->param()\*(C'\fR table onlyaffect the returned table object (the underlying C apr_table_t is\&\fIgenerated\fR from the parse data by \fIapreq_params()\fR). Modificationsdo not affect the actual request data, and will not be seen by otherlibapreq2 applications..Sh "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 areprovided in this release for backwards compatibility,however they are deprecated and may be removed from a futurerelease..Sh "body".IX Subsection "body".Vb 2\& $req\->body()\& $req\->body($name).Ve.PPReturns an \fIAPR::Request::Param::Table\fR object containing the \s-1POST\s0 dataparameters of the \fIApache2::Request\fR object..PP.Vb 1\& my $body = $req\->body;.Ve.PPAn optional name parameter can be passed to return the \s-1POST\s0 dataparameter associated with the given name:.PP.Vb 1\& my $foo_body = $req\->body("foo");.Ve.PPMore generally, \f(CW\*(C`body()\*(C'\fR follows the same pattern as \f(CW\*(C`param()\*(C'\fRwith respect to its return values and argument list. The main differenceis that modifications to the \f(CW\*(C`scalar $req\->body()\*(C'\fR table affectthe underlying apr_table_t attribute in apreq_request_t, so their impactwill be noticed by all libapreq2 applications during this request..Sh "upload".IX Subsection "upload".Vb 2\& $req\->upload()\& $req\->upload($name).Ve.PPRequires \f(CW\*(C`Apache2::Upload\*(C'\fR. With no arguments, this methodreturns an \fIAPR::Request::Param::Table\fR object in scalar context,or the names of all \fIApache2::Upload\fR objects in list context..PPAn optional name parameter can be passed to return the \fIApache2::Upload\fRobject associated with the given name:.PP.Vb 1\& my $upload = $req\->upload($name);.Ve.PPMore generally, \f(CW\*(C`upload()\*(C'\fR follows the same pattern as \f(CW\*(C`param()\*(C'\fRwith respect to its return values and argument list. The main differenceis that its returned values are Apache2::Upload object refs, notsimple scalars..PPNote: modifications to the \f(CW\*(C`scalar $req\->upload()\*(C'\fR table onlyaffect the returned table object (the underlying C apr_table_t is\&\fIgenerated\fR by \fIapreq_uploads()\fR). They do not affect the actual requestdata, and will not be seen by other libapreq2 applications..Sh "args_status".IX Subsection "args_status".Vb 1\& $req\->args_status().Ve.PPGet the \fI\s-1APR\s0\fR status code of the query-string parser.\&\s-1APR_SUCCESS\s0 on success, error otherwise..Sh "body_status".IX Subsection "body_status".Vb 1\& $req\->body_status().Ve.PPGet 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 parserhas more data to parse, \s-1APR_EINIT\s0 if no post data has been parsed,error otherwise..Sh "param_status".IX Subsection "param_status".Vb 1\& $req\->param_status().Ve.PPIn scalar context, this returns \f(CW\*(C`args_status\*(C'\fR if there wasan 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.PPIn list context \f(CW\*(C`param_status\*(C'\fR returns the list\&\f(CW\*(C`(args_status, body_status)\*(C'\fR..Sh "parse".IX Subsection "parse".Vb 1\& $req\->parse().Ve.PPForces the request to be parsed immediately. In void context,this will throw an APR::Request::Error should the either thequery-string or body parser fail. In all other contexts it willreturn the two parsers' combined \fI\s-1APR\s0\fR status code.PP.Vb 1\& $req\->body_status || $req\->args_status.Ve.PPHowever \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.PPCalling \f(CW\*(C`$r\->discard_request_body\*(C'\fR outside the content handleris 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\fRaround a lazy-parsing scheme, so calling \f(CW\*(C`parse\*(C'\fR should notaffect 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 actuallyinherit from Apache2::Request as long as the Apache2::Request object is stored inan attribute called \*(L"r\*(R" or \*(L"_r\*(R". (The Apache2::Request class effectively does thedelegation for you automagically, as long as it knows where to find theApache2::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 methodsfrom Apache2::Request 1.X. These issues need to beaddressed when porting 1.X apps to the new 2.X \s-1API\s0..IP "\(bu" 4Apache2::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" 4You 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..SH "SEE ALSO".IX Header "SEE ALSO"APR::Request::Param, APR::Request::Error, Apache2::Upload,Apache2::Cookie, \fIAPR::Table\fR\|(3)..SH "COPYRIGHT".IX Header "COPYRIGHT".Vb 1\& Copyright 2003\-2006 The Apache Software Foundation\&\& Licensed 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -