📄 requestrec.pm
字号:
too to the latest value.=item since: 2.0.00=backMost of the time, this method is used to get the C<finfo> member. Theonly reason you may want to set it is you need to use it before theApache's default map_to_storage phase is called.Examples:=over=item *What Apache thinks is the current request filename (post theC<L<PerlMapToStorageHandler|docs::2.0::user::handlers::http/PerlMapToStorageHandler>>phase): use Apache2::RequestRec (); use APR::Finfo (); print $r->finfo->fname;=item *Populate the C<finfo> member (normally, before theC<L<PerlMapToStorageHandler|docs::2.0::user::handlers::http/PerlMapToStorageHandler>>phase): use APR::Finfo (); use APR::Const -compile => qw(FINFO_NORM); my $finfo = APR::Finfo::stat(__FILE__, APR::Const::FINFO_NORM, $r->pool); $r->finfo($finfo);=back=head2 C<handler>Get/set the equivalent of the C<SetHandler> directive. $handler = $r->handler(); $prev_handler = $r->handler($new_handler);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_handler> ( string )the new handler.=item ret: C<$handler> ( string )the current handler.If C<$new_handler> is passed, the previous value is returned.=item since: 2.0.00=back=head2 C<header_only>Did the client has asked for headers only? e.g. if the request methodwas B<HEAD>. $status = $r->header_only();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$status> ( boolean )Returns true if the client is asking for headers only, false otherwise=item since: 2.0.00=back=head2 C<headers_in>Get/set the request MIME headers: $headers_in = $r->headers_in();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$headers_in>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )=item since: 2.0.00=backThis table is available starting from theC<L<PerlHeaderParserHandler|docs::2.0::user::handlers::http/PerlHeaderParserHandler>>phase.For example you can use it to retrieve the cookie value sent by theclient, in the C<Cookie:> header: my $cookie = $r->headers_in->{Cookie} || '';=head2 C<headers_out>Get/set MIME response headers, printed only on 2xx responses. $headers_out = $r->headers_out();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$headers_out>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )=item since: 2.0.00=backSee also C<L<err_headers_out|/C_err_headers_out_>>, which allows toset headers for non-2xx responses and persist across internalredirects.=head2 C<hostname>Host, as set by full URI or Host: $hostname = $r->hostname(); $prev_hostname = $r->hostname($new_hostname);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_hostname> ( string )new value=item ret: C<$hostname> ( string )the current hostname, or the previous value if the optionalC<$new_hostname> argument was passed=item since: 2.0.00=back=head2 C<input_filters>Get/set the first filter in a linked list of request level inputfilters: $input_filters = $r->input_filters(); $prev_input_filters = $r->input_filters($new_input_filters);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_input_filters>Set a new value=item ret: C<$input_filters>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The first filter in the request level input filters chain.If C<$new_input_filters> was passed, returns the previous value.=item since: 2.0.00=backFor example instead of usingC<L<$r-E<gt>read()|docs::2.0::api::Apache2::RequestIO/C_read_>> to readthe POST data, one could use an explicit walk through incoming bucketbrigades to get that data. The following function C<read_post()> doesjust that (in fact that's whatC<L<$r-E<gt>read()|docs::2.0::api::Apache2::RequestIO/C_read_>> doesbehind the scenes): use APR::Brigade (); use APR::Bucket (); use Apache2::Filter (); use Apache2::Const -compile => qw(MODE_READBYTES); use APR::Const -compile => qw(SUCCESS BLOCK_READ); use constant IOBUFSIZE => 8192; sub read_post { my $r = shift; my $bb = APR::Brigade->new($r->pool, $r->connection->bucket_alloc); my $data = ''; my $seen_eos = 0; do { $r->input_filters->get_brigade($bb, Apache2::Const::MODE_READBYTES, APR::Const::BLOCK_READ, IOBUFSIZE); for (my $b = $bb->first; $b; $b = $bb->next($b)) { if ($b->is_eos) { $seen_eos++; last; } if ($b->read(my $buf)) { $data .= $buf; } $b->remove; # optimization to reuse memory } } while (!$seen_eos); $bb->destroy; return $data; }As you can see C<$r-E<gt>input_filters> gives us a pointer to the lastof the top of the incoming filters stack.=head2 C<main>Get the main request record $main_r = $r->main();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$main_r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )If the current request is a sub-request, this method returns a blessedreference to the main request structure. If the current request is themain request, then this method returns C<undef>.To figure out whether you are inside a main request or asub-request/internal redirect, useC<L<$r-E<gt>is_initial_req|docs::2.0::api::Apache2::RequestUtil/C_is_initial_req_>>.=item since: 2.0.00=back=head2 C<method>Get/set the current request method (e.g. C<GET>, C<HEAD>, C<POST>, etc.): $method = $r->method(); $pre_method = $r->method($new_method);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_method> ( string )a new value=item ret: C<$method> ( string )The current method as a stringif C<$new_method> was passed the previous value is returned.=item since: 2.0.00=back=head2 C<method_number>Get/set the HTTP method, issued by the client (C<Apache2::Const::M_GET>,C<Apache2::Const::M_POST>, etc.) $methnum = $r->method_number(); $prev_methnum = $r->method_number($new_methnum);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_methnum> ( C<L<Apache2::Const :methodsconstant|docs::2.0::api::Apache2::Const/C__methods_>> )a new value=item ret: C<$methnum> ( C<L<Apache2::Const :methodsconstant|docs::2.0::api::Apache2::Const/C__methods_>> )The current method as a numberif C<$new_methnum> was passed the previous value is returned.=item since: 2.0.00=backSee the C<L<$r-E<gt>allowed|/C_allowed_>> entry for examples.=head2 C<mtime>Last modified time of the requested resource $mtime = $r->mtime(); $prev_mtime = $r->mtime($new_mtime);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_mtime> (epoch seconds).a new value=item ret: C<$mtime> (epoch seconds).the current valueif C<$new_mtime> was passed the previous value is returned.=item since: 2.0.00=back=head2 C<next>Pointer to the redirected request if this is an external redirect $next_r = $r->next();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$next_r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )returns a blessed reference to the next (internal) request structureor C<undef> if there is no next request.=item since: 2.0.00=back=head2 C<no_local_copy>There is no local copy of this response $status = $r->no_local_copy();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$status> (integer)=item since: 2.0.00=backUsed internally in certain sub-requests to prevent sendingC<Apache2::Const::HTTP_NOT_MODIFIED> for a fragment or error documents. Forexample see the implementation in F<modules/filters/mod_include.c>.Also used internally inC<L<$r-E<gt>meets_conditions|docs::2.0::api::Apache2::Response/C_meets_conditions_>>-- if set to a true value, the conditions are always met.=head2 C<notes>Get/set text notes for the duration of this request. These notes canbe passed from one module to another (not only mod_perl, but modulesin any other language): $notes = $r->notes(); $prev_notes = $r->notes($new_notes);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_notes>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )=item ret: C<$notes>( C<L<APR::Table object|docs::2.0::api::APR::Table>> )the current notes table.if the C<$new_notes> argument was passed, returns the previous value.=item since: 2.0.00=backIf you want to pass Perl structures, you can useC<L<$r-E<gt>pnotes|docs::2.0::api::Apache2::RequestUtil/C_pnotes_>>.Also seeC<L<$c-E<gt>notes|docs::2.0::api::Apache2::Connection/C_notes_>>=head2 C<output_filters>Get the first filter in a linked list of request level output filters: $output_filters = $r->output_filters(); $prev_output_filters = $r->output_filters($new_output_filters);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$new_output_filters>Set a new value=item ret: C<$output_filters>( C<L<Apache2::Filter object|docs::2.0::api::Apache2::Filter>> )The first filter in the request level output filters chain.If C<$new_output_filters> was passed, returns the previous value.=item since: 2.0.00=backFor example instead of usingC<L<$r-E<gt>print()|docs::2.0::api::Apache2::RequestIO/C_print_>> tosend the response body, one could send the data directly to the firstoutput filter. The following function C<send_response_body()> doesjust that: use APR::Brigade (); use APR::Bucket (); use Apache2::Filter (); sub send_response_body { my ($r, $data) = @_; my $bb = APR::Brigade->new($r->pool, $r->connection->bucket_alloc); my $b = APR::Bucket->new($bb->bucket_alloc, $data); $bb->insert_tail($b); $r->output_filters->fflush($bb); $bb->destroy; }In fact that's whatC<L<$r-E<gt>read()|docs::2.0::api::Apache2::RequestIO/C_read_>> doesbehind the scenes. But it also knows to parse HTTP headers passedtogether with the data and it also implements buffering, which theabove function does not.=head2 C<path_info>Get/set the C<PATH_INFO>, what is left in the path after the I<URI--E<gt> filename> translation: $path_info = $r->path_info(); $prev_path_info = $r->path_info($path_info);=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item opt arg1: C<$path_info> ( string )Set a new value=item ret: C<$path_info> ( string )Return the current value.If the optional argument C<$path_info> is passed, the previous valueis returned.=item since: 2.0.00=back=head2 C<per_dir_config>Get the dir config vector: $per_dir_config = $r->per_dir_config();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$per_dir_config>( C<L<Apache2::ConfVector object|docs::2.0::api::Apache2::ConfVector>> )=item since: 2.0.00=backFor an indepth discussion, refer to the L<Apache Server ConfigurationCustomization in Perl chapter|docs::2.0::user::config::custom>.=head2 C<pool>The pool associated with the request $p = $r->pool();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$p> ( C<L<APR::Pool object|docs::2.0::api::APR::Pool>> )=item since: 2.0.00=back=head2 C<prev>Pointer to the previous request if this is an internal redirect $prev_r = $r->prev();=over 4=item obj: C<$r>( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )=item ret: C<$prev_r> ( C<L<Apache2::RequestRec object|docs::2.0::api::Apache2::RequestRec>> )a blessed reference to the previous (internal) request structure orC<undef> if there is no previous request.=item since: 2.0.00=back=head2 C<proto_input_filters>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -