📄 requestrec.pm
字号:
Get the first filter in a linked list of protocol level input filters: $proto_input_filters = $r->proto_input_filters(); $prev_proto_input_filters = $r->proto_input_filters($new_proto_input_filters);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_proto_input_filters>Set a new value=item ret: C<$proto_input_filters>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The first filter in the protocol level input filters chain.If C<$new_proto_input_filters> was passed, returns the previous value.=item since: 2.0.00=backC<$r-E<gt>proto_input_filters> points to the same filter asC<L<$r-E<gt>connection-E<gt>input_filters|docs::2.0::api::Apache2::Connection/C_input_filters_>>.=head2 C<proto_num>Get current request's HTTP protocol version number $proto_num = $r->proto_num();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$proto_num> (integer)current request's HTTP protocol version number, e.g.: HTTP/1.0 ==1000, HTTP/1.1 = 1001=item since: 2.0.00=back=head2 C<proto_output_filters>Get the first filter in a linked list of protocol level outputfilters: $proto_output_filters = $r->proto_output_filters(); $prev_proto_output_filters = $r->proto_output_filters($new_proto_output_filters);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_proto_output_filters>Set a new value=item ret: C<$proto_output_filters>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The first filter in the protocol level output filters chain.If C<$new_proto_output_filters> was passed, returns the previous value.=item since: 2.0.00=backC<$r-E<gt>proto_output_filters> points to the same filter asC<L<$r-E<gt>connection-E<gt>output_filters|docs::2.0::api::Apache2::Connection/C_output_filters_>>.=head2 C<protocol>Get a string identifying the protocol that the client speaks. $protocol = $r->protocol();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$protocl> ( string )Typical values are C<"HTTP/1.0"> or C<"HTTP/1.1">.If the client didn't specify the protocol version, the default isC<"HTTP/0.9">=item since: 2.0.00=back=head2 C<proxyreq>Get/set the I<proxyrec> request record member and optionally adjustother related fields. $status = $r->proxyreq($val);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$val> ( integer )0, 1 or none.=item ret: C<$status> ( integer )If C<$val> is 0 or 1, the I<proxyrec> member will be set to that valueand previous value will be returned.If C<$val> is not passed, and C<$r-E<gt>proxyreq> is not true, and theproxy request is matching the current vhost (scheme, hostname andport), the I<proxyrec> member will be set to 1 and that value will bereturned. In addition C<$r-E<gt>uri> is set to C<$r-E<gt>unparsed_uri>and C<$r-E<gt>filename> is set to C<"modperl-proxy:".$r-E<gt>uri>. Ifthose conditions aren't true 0 is returned.=item since: 2.0.00=backFor example to turn a normal request into a proxy request to behandled on the same server in the C<PerlTransHandler> phase run: my $real_url = $r->unparsed_uri; $r->proxyreq(1); $r->uri($real_url); $r->filename("proxy:$real_url"); $r->handler('proxy-server');Also remember that if you want to turn a proxy request into anon-proxy request, it's not enough to call: $r->proxyreq(0);You need to adjust C<$r-E<gt>uri> and C<$r-E<gt>filename> as well ifyou run that code in C<PerlPostReadRequestHandler> phase, since if youdon't -- C<mod_proxy>'s own post_read_request handler will overrideyour settings (as it will run after the mod_perl handler).=head2 C<request_time>Time when the request started $request_time = $r->request_time();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$request_time> (epoch seconds).=item since: 2.0.00=back=head2 C<server>Get the C<L<Apache2::Server|docs::2.0::api::Apache2::ServerRec>> object forthe server the request C<$r> is running under. $s = $r->server();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$s>( C<L<Apache2::ServerRec object|docs::2.0::api::Apache2::ServerRec>> )=item since: 2.0.00=back=head2 C<status>Get/set the reply status for the client request. $status = $r->status(); $prev_status = $r->status($new_status);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_status> ( integer )If C<$new_status> is passed the new status is assigned.Normally you would use some C<L<Apache2::Constconstant|docs::2.0::api::Apache2::Const>>, e.g. C<Apache2::Const::REDIRECT>.=item ret: C<$newval> ( integer )The current value.If C<$new_status> is passed the old value is returned.=item since: 2.0.00=backUsually you will set this value indirectly by returning the statuscode as the handler's function result. However, there are rareinstances when you want to trick Apache into thinking that the modulereturned an C<Apache2::Const::OK> status code, but actually send the browser anon-OK status. This may come handy when implementing an HTTP proxyhandler. The proxy handler needs to send to the client, whateverstatus code the proxied server has returned, while returningC<Apache2::Const::OK> to Apache. e.g.: $r->status($some_code); return Apache2::Const::OKSee also C<L<$r-E<gt>status_line|/C_status_line_>>, which. if set,overrides C<$r-E<gt>status>.=head2 C<status_line>Get/set the response status line. The status line is a string like"200 Document follows" and it will take precedence over the valuespecified using the C<$r-E<gt>status()> described above. $status_line = $r->status_line(); $prev_status_line = $r->status_line($new_status_line);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_status_line> ( string )=item ret: C<$status_line> ( string )=item since: 2.0.00=backWhen discussing C<L<$r-E<gt>status|/C_status_>> we have mentioned thatsometimes a handler runs to a successful completion, but may need toreturn a different code, which is the case with the proxyserver. Assuming that the proxy handler forwards to the clientwhatever response the proxied server has sent, it'll usually useC<status_line()>, like so: $r->status_line($response->code() . ' ' . $response->message()); return Apache2::Const::OK;In this example C<$response> could be for example an C<HTTP::Response>object, if C<LWP::UserAgent> was used to implement the proxy.This method is also handy when you extend the HTTP protocol and addnew response codes. For example you could invent a new error code andtell Apache to use that in the response like so: $r->status_line("499 We have been FooBared"); return Apache2::Const::OK;Here C<499> is the new response code, and I<We have been FooBared> isthe custom response message.=head2 C<subprocess_env>Get/set the Apache C<subprocess_env> table, or optionally set thevalue of a named entry. $r->subprocess_env; $env_table = $r->subprocess_env; $r->subprocess_env($key => $val); $val = $r->subprocess_env($key);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$key> ( string )=item opt arg2: C<$val> ( string )=item ret: C<...>=item since: 2.0.00=backWhen called in VOID context with no arguments, it populate C<%ENV>with special variables (e.g. C<$ENV{QUERY_STRING}>) like mod_cgidoes.When called in a non-VOID context with no arguments, it returns anC<L<APR::Table object|docs::2.0::api::APR::Table>>.When the C<$key> argument (string) is passed, it returns thecorresponding value (if such exists, or C<undef>. The following twolines are equivalent: $val = $r->subprocess_env($key); $val = $r->subprocess_env->get($key);When the C<$key> and the C<$val> arguments (strings) are passed, thevalue is set. The following two lines are equivalent: $r->subprocess_env($key => $val); $r->subprocess_env->set($key => $val);The C<subprocess_env> C<L<table|docs::2.0::api::APR::Table>> is usedby C<L<Apache2::SubProcess|docs::2.0::api::Apache2::SubProcess>>, topass environment variables to externally spawned processes. It's alsoused by various Apache modules, and you should use this table to passthe environment variables. For example if inC<PerlHeaderParserHandler> you do: $r->subprocess_env(MyLanguage => "de");you can then deploy C<mod_include> and write in I<.shtml> document: <!--#if expr="$MyLanguage = en" --> English <!--#elif expr="$MyLanguage = de" --> Deutsch <!--#else --> Sorry <!--#endif -->=head2 C<the_request>First HTTP request header $request = $r->the_request();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$request> ( string )For example: GET /foo/bar/my_path_info?args=3 HTTP/1.0=item since: 2.0.00=back=head2 C<unparsed_uri>The URI without any parsing performed $unparsed_uri = $r->unparsed_uri();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$unparsed_uri> ( string )=item since: 2.0.00=backIf for example the request was: GET /foo/bar/my_path_info?args=3 HTTP/1.0C<L<$r-E<gt>uri|/C_uri_>> returns: /foo/bar/my_path_infowhereas C<$r-E<gt>unparsed_uri> returns: /foo/bar/my_path_info?args=3=head2 C<uri>The path portion of the URI $uri = $r->uri(); my $prec_uri = $r->uri($new_uri);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_uri> ( string )=item ret: C<$uri> ( string )=item since: 2.0.00=backSee the example in the C<L<$r-E<gt>unparsed_uri|/C_unparsed_uri_>>section.=head2 C<user>Get the user name, if an L<authentication> process was successful. Orset it. $user = $r->user(); $prev_user = $r->user($new_user);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_user> ( string )Pass C<$new_user> to set a new value=item ret: C<$user> ( string )The current username if an authentication process was successful.If C<$new_user> was passed, the previous value is returned.=item since: 2.0.00=backFor example, let's print the username passed by the client: my ($res, $sent_pw) = $r->get_basic_auth_pw; return $res if $res != Apache2::Const::OK; print "User: ", $r->user;=head1 Unsupported APIC<Apache2::RequestRec> also provides auto-generated Perl interface fora few other methods which aren't tested at the moment and thereforetheir API is a subject to change. These methods will be finalizedlater as a need arises. If you want to rely on any of the followingmethods please contact the L<the mod_perl development mailinglist|maillist::dev> so we can help each other take the steps necessaryto shift the method to an officially supported API.=head2 C<allowed_methods>META: Autogenerated - needs to be reviewed/completedList of allowed methods $list = $r->allowed_methods();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$list>( C<L<Apache2::MethodList object|docs::2.0::api::Apache2::MethodList>> )=item since: 2.0.00=backMETA: Apache2::MethodList is not available at the moment=head2 C<allowed_xmethods>META: Autogenerated - needs to be reviewed/completedArray of extension methods $array = $r->allowed_xmethods();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$array>( C<L<APR::ArrayHeader object|docs::2.0::api::APR::ArrayHeader>> )=item since: 2.0.00=backMETA: APR::ArrayHeader is not available at the moment=head2 C<request_config>Config vector containing pointers to request's per-server configstructures $ret = $r->request_config($newval);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$newval>( C<L<Apache2::ConfVector object|docs::2.0::api::Apache2::ConfVector>> )=item since: 2.0.00=back=head2 C<used_path_info>META: Autogenerated - needs to be reviewed/completedFlag for the handler to accept or reject path_info onthe current request. All modules should respect theAP_REQ_ACCEPT_PATH_INFO and AP_REQ_REJECT_PATH_INFOvalues, while AP_REQ_DEFAULT_PATH_INFO indicates theymay follow existing conventions. This is set to theuser's preference upon HOOK_VERY_FIRST of the fixups. $ret = $r->used_path_info($newval);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item arg1: C<$newval> (integer)=item since: 2.0.00=back=head1 See AlsoL<mod_perl 2.0 documentation|docs::2.0::index>.=head1 Copyrightmod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0.=head1 AuthorsL<The mod_perl development team and numerouscontributors|about::contributors::people>.=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -