📄 apache2::requestutil.3
字号:
.Ve.PPTo receive a list of values you must use \f(CW\*(C`get()\*(C'\fR method from the\&\f(CW\*(C`APR::Table\*(C'\fR class..PP.Vb 1\& $r\->dir_config($key => $val);.Ve.PPIf the \f(CW$key\fR and the \f(CW$val\fR arguments are used, the \fIset()\fR operationwill happen: all existing values associated with the key \f(CW$key\fR (andthe key itself) will be deleted and \f(CW$value\fR will be placed instead..PP.Vb 1\& $r\->dir_config($key => undef);.Ve.PPIf \f(CW$val\fR is \fIundef\fR the \fIunset()\fR operation will happen: all existingvalues associated with the key \f(CW$key\fR (and the key itself) will bedeleted..ie n .Sh """document_root""".el .Sh "\f(CWdocument_root\fP".IX Subsection "document_root"Retrieve the document root for this server.PP.Vb 2\& $docroot = $r\->document_root();\& $docroot = $r\->document_root($new_root);.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )"The current request.ie n .IP "opt arg1: $new_root" 4.el .IP "opt arg1: \f(CW$new_root\fR" 4.IX Item "opt arg1: $new_root"Sets the document root to a new value \fBonly for the duration of thecurrent request\fR..SpNote the limited functionality under threadedMPMs..ie n .IP "ret: $docroot ( string )" 4.el .IP "ret: \f(CW$docroot\fR ( string )" 4.IX Item "ret: $docroot ( string )"The document root.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".ie n .Sh """get_handlers""".el .Sh "\f(CWget_handlers\fP".IX Subsection "get_handlers"Returns a reference to a list of handlers enabled for a given phase..PP.Vb 1\& $handlers_list = $r\->get_handlers($hook_name);.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )".PD 0.ie n .IP "arg1: $hook_name ( string )" 4.el .IP "arg1: \f(CW$hook_name\fR ( string )" 4.IX Item "arg1: $hook_name ( string )".PDa string representing the phase to handle (e.g. \f(CW\*(C`PerlLogHandler\*(C'\fR).ie n .IP "ret: $handlers_list (ref to an \s-1ARRAY\s0 of \s-1CODE\s0 refs)" 4.el .IP "ret: \f(CW$handlers_list\fR (ref to an \s-1ARRAY\s0 of \s-1CODE\s0 refs)" 4.IX Item "ret: $handlers_list (ref to an ARRAY of CODE refs)"a list of handler subroutines \s-1CODE\s0 references.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPSee also:\&\f(CW\*(C`$s\->add_config\*(C'\fR.PPFor example:.PPA list of handlers configured to run at the response phase:.PP.Vb 1\& my @handlers = @{ $r\->get_handlers(\*(AqPerlResponseHandler\*(Aq) || [] };.Ve.ie n .Sh """get_limit_req_body""".el .Sh "\f(CWget_limit_req_body\fP".IX Subsection "get_limit_req_body"Return the limit on bytes in request msg body.PP.Vb 1\& $limit = $r\->get_limit_req_body();.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )"The current request.ie n .IP "ret: $limit (integer)" 4.el .IP "ret: \f(CW$limit\fR (integer)" 4.IX Item "ret: $limit (integer)"the maximum number of bytes in the request msg body.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".ie n .Sh """get_server_name""".el .Sh "\f(CWget_server_name\fP".IX Subsection "get_server_name"Get the current request's server name.PP.Vb 1\& $server = $r\->get_server_name();.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )"The current request.ie n .IP "ret: $server ( string )" 4.el .IP "ret: \f(CW$server\fR ( string )" 4.IX Item "ret: $server ( string )"the server name.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPFor example, consruct a hostport string:.PP.Vb 2\& use Apache2::RequestUtil ();\& my $hostport = join \*(Aq:\*(Aq, $r\->get_server_name, $r\->get_server_port;.Ve.ie n .Sh """get_server_port""".el .Sh "\f(CWget_server_port\fP".IX Subsection "get_server_port"Get the current server port.PP.Vb 1\& $port = $r\->get_server_port();.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )"The current request.ie n .IP "ret: $port ( integer )" 4.el .IP "ret: \f(CW$port\fR ( integer )" 4.IX Item "ret: $port ( integer )"The server's port number.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPFor example, consruct a hostport string:.PP.Vb 2\& use Apache2::RequestUtil ();\& my $hostport = join \*(Aq:\*(Aq, $r\->get_server_name, $r\->get_server_port;.Ve.ie n .Sh """get_status_line""".el .Sh "\f(CWget_status_line\fP".IX Subsection "get_status_line"Return the \f(CW\*(C`Status\-Line\*(C'\fR for a given status code (excluding theHTTP-Version field)..PP.Vb 1\& $status_line = Apache2::RequestUtil::get_status_line($status);.Ve.ie n .IP "arg1: $status (integer)" 4.el .IP "arg1: \f(CW$status\fR (integer)" 4.IX Item "arg1: $status (integer)"The \s-1HTTP\s0 status code.ie n .IP "ret: $status_line ( string )" 4.el .IP "ret: \f(CW$status_line\fR ( string )" 4.IX Item "ret: $status_line ( string )"The Status-Line.SpIf an invalid or unknown status code is passed, \f(CW"500 Internal ServerError"\fR will be returned..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPFor example:.PP.Vb 2\& use Apache2::RequestUtil ();\& print Apache2::RequestUtil::get_status_line(400);.Ve.PPwill print:.PP.Vb 1\& 400 Bad Request.Ve.ie n .Sh """is_initial_req""".el .Sh "\f(CWis_initial_req\fP".IX Subsection "is_initial_req"Determine whether the current request is the main request or asub-request.PP.Vb 1\& $is_initial = $r\->is_initial_req();.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )"A request or a sub-request object.ie n .IP "ret: $is_initial ( boolean )" 4.el .IP "ret: \f(CW$is_initial\fR ( boolean )" 4.IX Item "ret: $is_initial ( boolean )"If true \*(-- it's the main request, otherwise it's a sub-request.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".ie n .Sh """is_perl_option_enabled""".el .Sh "\f(CWis_perl_option_enabled\fP".IX Subsection "is_perl_option_enabled"check whether a directory level \f(CW\*(C`PerlOptions\*(C'\fR flag is enabled or not..PP.Vb 1\& $result = $r\->is_perl_option_enabled($flag);.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )".PD 0.ie n .IP "arg1: $flag ( string )" 4.el .IP "arg1: \f(CW$flag\fR ( string )" 4.IX Item "arg1: $flag ( string )".ie n .IP "ret: $result ( boolean )" 4.el .IP "ret: \f(CW$result\fR ( boolean )" 4.IX Item "ret: $result ( boolean )".IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.PPFor example to check whether the \f(CW\*(C`SetupEnv\*(C'\fR option is enabled for thecurrent request (which can be disabled with \f(CW\*(C`PerlOptions \-SetupEnv\*(C'\fR)and populate the environment variables table if disabled:.PP.Vb 1\& $r\->subprocess_env unless $r\->is_perl_option_enabled(\*(AqSetupEnv\*(Aq);.Ve.PPSee also:PerlOptions andthe equivalent function for server level PerlOptionsflags..ie n .Sh """location""".el .Sh "\f(CWlocation\fP".IX Subsection "location"Get the path of the <Location> section from which the current\&\f(CW\*(C`Perl*Handler\*(C'\fR is being called..PP.Vb 1\& $location = $r\->location();.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )".PD 0.ie n .IP "ret: $location ( string )" 4.el .IP "ret: \f(CW$location\fR ( string )" 4.IX Item "ret: $location ( string )".IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.ie n .Sh """location_merge""".el .Sh "\f(CWlocation_merge\fP".IX Subsection "location_merge"Merge a given \f(CW\*(C`<Location<\*(C'\fR container into the current requestobject:.PP.Vb 1\& $ret = $r\->location_merge($location);.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )".PD 0.ie n .IP "arg1: $location ( string )" 4.el .IP "arg1: \f(CW$location\fR ( string )" 4.IX Item "arg1: $location ( string )".PDThe argument in a \f(CW\*(C`<Location<\*(C'\fR section. For example to mergea container:.Sp.Vb 3\& <Location /foo>\& ...\& </Location>.Ve.Spthat argument will be \fI/foo\fR.ie n .IP "ret: $ret ( boolean )" 4.el .IP "ret: \f(CW$ret\fR ( boolean )" 4.IX Item "ret: $ret ( boolean )"a true value if the merge was successful (i.e. the request\&\f(CW$location\fR match was found), otherwise false..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPUseful for insertion of a configuration section into a custom\&\f(CW\*(C`Apache2::RequestRec\*(C'\fR object, created via the\&\f(CW\*(C`Apache2::RequestRec\->new()\*(C'\fR method. See for example the CommandServer protocolexample..ie n .Sh """new""".el .Sh "\f(CWnew\fP".IX Subsection "new"Create a new \f(CW\*(C`Apache2::RequestRec\*(C'\fR object..PP.Vb 2\& $r = Apache2::RequestRec\->new($c);\& $r = Apache2::RequestRec\->new($c, $pool);.Ve.ie n .IP "obj: ""Apache2::RequestRec""\fR ( \f(CW""Apache2::RequestRec class name"" )" 4.el .IP "obj: \f(CWApache2::RequestRec\fR ( \f(CWApache2::RequestRec class name\fR )" 4.IX Item "obj: Apache2::RequestRec ( Apache2::RequestRec class name )".PD 0.ie n .IP "arg1: $c\fR (\f(CW""Apache2::Connection object"")" 4.el .IP "arg1: \f(CW$c\fR (\f(CWApache2::Connection object\fR)" 4.IX Item "arg1: $c (Apache2::Connection object)".ie n .IP "opt arg2: $pool" 4.el .IP "opt arg2: \f(CW$pool\fR" 4.IX Item "opt arg2: $pool".PDIf no \f(CW$pool\fR argument is passed, \f(CW\*(C`$c\->pool\*(C'\fR is used. That meansthat the created \f(CW\*(C`Apache2::RequestRec\*(C'\fR object will be valid as long asthe connection object is valid..ie n .IP "ret: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "ret: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "ret: $r ( Apache2::RequestRec object )".PD 0.IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PD.PPIt's possible to reuse the \s-1HTTP\s0 framework features outside thefamiliar \s-1HTTP\s0 request cycle. It's possible to write your own full orpartial \s-1HTTP\s0 implementation without needing a running Apacheserver. You will need the \f(CW\*(C`Apache2::RequestRec\*(C'\fR object in order to beable to reuse the rich functionality supplied via this object..PPSee for example the Command Server protocolexample whichreuses \s-1HTTP\s0 \s-1AAA\s0 model under non-HTTP protocol..ie n .Sh """no_cache""".el .Sh "\f(CWno_cache\fP".IX Subsection "no_cache"Add/remove cache control headers:.PP.Vb 1\& $prev_no_cache = $r\->no_cache($boolean);.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4.el .IP "obj: \f(CW$r\fR ( \f(CWApache2::RequestRec object\fR )" 4.IX Item "obj: $r ( Apache2::RequestRec object )".PD 0.ie n .IP "arg1: $boolean ( boolean )" 4.el .IP "arg1: \f(CW$boolean\fR ( boolean )" 4.IX Item "arg1: $boolean ( boolean )".PDA true value sets the \f(CW\*(C`no_cache\*(C'\fR request record member to a truevalue and inserts:.Sp.Vb 2\& Pragma: no\-cache\& Cache\-control: no\-cache.Ve.Spinto the response headers, indicating that the data being returned isvolatile and the client should not cache it..SpA false value unsets the \f(CW\*(C`no_cache\*(C'\fR request record member and thementioned headers if they were previously set..ie n .IP "ret: $prev_no_cache ( boolean )" 4.el .IP "ret: \f(CW$prev_no_cache\fR ( boolean )" 4.IX Item "ret: $prev_no_cache ( boolean )"Should you care, the \f(CW\*(C`no_cache\*(C'\fR request record member value prior tothe change is returned..IP "since: 2.0.00" 4.IX Item "since: 2.0.00".PPThis method should be invoked before any response data has been sentout..ie n .Sh """pnotes""".el .Sh "\f(CWpnotes\fP".IX Subsection "pnotes"Share Perl variables between Perl \s-1HTTP\s0 handlers.PP.Vb 3\& $old_val = $r\->pnotes($key => $val);\& $val = $r\->pnotes($key);\& $hash_ref = $r\->pnotes();.Ve.ie n .IP "obj: $r\fR ( \f(CW""Apache2::RequestRec object"" )" 4
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -