.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" 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 .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . 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 "docs::api::Apache2::SubRequest 3pm" .TH docs::api::Apache2::SubRequest 3pm 2024-01-10 "perl v5.38.2" "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::SubRequest \- Perl API for Apache subrequests .SH Synopsis .IX Header "Synopsis" .Vb 1 \& use Apache2::SubRequest (); \& \& # run internal redirects at once \& $r\->internal_redirect($new_uri); \& $r\->internal_redirect_handler($new_uri); \& \& # create internal redirect objects \& $subr = $r\->lookup_uri("/foo"); \& $subr = $r\->lookup_method_uri("GET", "/tmp/bar") \& $subr = $r\->lookup_file("/tmp/bar"); \& # optionally manipulate the output through main request filters \& $subr = $r\->lookup_uri("/foo", $r\->output_filters); \& # now run them \& my $rc = $subr\->run; .Ve .SH Description .IX Header "Description" \&\f(CW\*(C`Apache2::SubRequest\*(C'\fR contains API for creating and running of Apache sub-requests. .PP \&\f(CW\*(C`Apache2::SubRequest\*(C'\fR is a sub-class of \f(CW\*(C`Apache2::RequestRec object\*(C'\fR. .SH API .IX Header "API" \&\f(CW\*(C`Apache2::SubRequest\*(C'\fR provides the following functions and/or methods: .ie n .SS """DESTROY""" .el .SS \f(CWDESTROY\fP .IX Subsection "DESTROY" Free the memory associated with a sub request: .PP .Vb 1 \& undef $subr; # but normally don\*(Aqt do that .Ve .ie n .IP "obj: $subr ( ""Apache2::SubRequest object"" )" 4 .el .IP "obj: \f(CW$subr\fR ( \f(CWApache2::SubRequest object\fR )" 4 .IX Item "obj: $subr ( Apache2::SubRequest object )" The sub request to finish .IP "ret: no return value" 4 .IX Item "ret: no return value" .PD 0 .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP \&\f(CW\*(C`DESTROY\*(C'\fR is called automatically when \f(CW$subr\fR goes out of scope. .PP If you want to free the memory earlier than that (for example if you run several subrequests), you can \f(CW\*(C`undef\*(C'\fR the object as: .PP .Vb 1 \& undef $subr; .Ve .PP but never call \f(CW\*(C`DESTROY\*(C'\fR explicitly, since it'll result in \&\f(CW\*(C`ap_destroy_sub_req\*(C'\fR being called more than once, resulting in multiple brain injuries and certain hair loss. .ie n .SS """internal_redirect""" .el .SS \f(CWinternal_redirect\fP .IX Subsection "internal_redirect" Redirect the current request to some other uri internally .PP .Vb 1 \& $r\->internal_redirect($new_uri); .Ve .ie n .IP "obj: $r ( ""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 "arg1: $new_uri ( string )" 4 .el .IP "arg1: \f(CW$new_uri\fR ( string )" 4 .IX Item "arg1: $new_uri ( string )" The URI to replace the current request with .IP "ret: no return value" 4 .IX Item "ret: no return value" .PD 0 .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP In case that you want some other request to be served as the top-level request instead of what the client requested directly, call this method from a handler, and then immediately return \f(CW\*(C`Apache2::Const::OK\*(C'\fR. The client will be unaware the a different request was served to her behind the scenes. .ie n .SS """internal_redirect_handler""" .el .SS \f(CWinternal_redirect_handler\fP .IX Subsection "internal_redirect_handler" Identical to \f(CW\*(C`internal_redirect\*(C'\fR, plus automatically sets \&\f(CW\*(C`$r\->content_type\*(C'\fR is of the sub-request to be the same as of the main request, if \&\f(CW\*(C`$r\->handler\*(C'\fR is true. .PP .Vb 1 \& $r\->internal_redirect_handler($new_uri); .Ve .ie n .IP "obj: $r ( ""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 "arg1: $new_uri ( string )" 4 .el .IP "arg1: \f(CW$new_uri\fR ( string )" 4 .IX Item "arg1: $new_uri ( string )" The URI to replace the current request with. .IP "ret: no return value" 4 .IX Item "ret: no return value" .PD 0 .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP This function is designed for things like actions or CGI scripts, when using \f(CW\*(C`AddHandler\*(C'\fR, and you want to preserve the content type across an internal redirect. .ie n .SS """lookup_file""" .el .SS \f(CWlookup_file\fP .IX Subsection "lookup_file" Create a subrequest for the given file. This sub request can be inspected to find information about the requested file .PP .Vb 2 \& $ret = $r\->lookup_file($new_file); \& $ret = $r\->lookup_file($new_file, $next_filter); .Ve .ie n .IP "obj: $r ( ""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 "arg1: $new_file ( string )" 4 .el .IP "arg1: \f(CW$new_file\fR ( string )" 4 .IX Item "arg1: $new_file ( string )" The file to lookup .ie n .IP "opt arg2: $next_filter ( ""Apache2::Filter"" )" 4 .el .IP "opt arg2: \f(CW$next_filter\fR ( \f(CWApache2::Filter\fR )" 4 .IX Item "opt arg2: $next_filter ( Apache2::Filter )" See \f(CW\*(C`$r\->lookup_uri\*(C'\fR for details. .ie n .IP "ret: $ret ( ""Apache2::SubRequest object"" )" 4 .el .IP "ret: \f(CW$ret\fR ( \f(CWApache2::SubRequest object\fR )" 4 .IX Item "ret: $ret ( Apache2::SubRequest object )" The sub request record. .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP See \f(CW\*(C`$r\->lookup_uri\*(C'\fR for further discussion. .ie n .SS """lookup_method_uri""" .el .SS \f(CWlookup_method_uri\fP .IX Subsection "lookup_method_uri" Create a sub request for the given URI using a specific method. This sub request can be inspected to find information about the requested URI .PP .Vb 2 \& $ret = $r\->lookup_method_uri($method, $new_uri); \& $ret = $r\->lookup_method_uri($method, $new_uri, $next_filter); .Ve .ie n .IP "obj: $r ( ""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 "arg1: $method ( string )" 4 .el .IP "arg1: \f(CW$method\fR ( string )" 4 .IX Item "arg1: $method ( string )" The method to use in the new sub request (e.g. \f(CW"GET"\fR) .ie n .IP "arg2: $new_uri ( string )" 4 .el .IP "arg2: \f(CW$new_uri\fR ( string )" 4 .IX Item "arg2: $new_uri ( string )" The URI to lookup .ie n .IP "opt arg3: $next_filter ( ""Apache2::Filter object"" )" 4 .el .IP "opt arg3: \f(CW$next_filter\fR ( \f(CWApache2::Filter object\fR )" 4 .IX Item "opt arg3: $next_filter ( Apache2::Filter object )" See \f(CW\*(C`$r\->lookup_uri\*(C'\fR for details. .ie n .IP "ret: $ret ( ""Apache2::SubRequest object"" )" 4 .el .IP "ret: \f(CW$ret\fR ( \f(CWApache2::SubRequest object\fR )" 4 .IX Item "ret: $ret ( Apache2::SubRequest object )" The sub request record. .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP See \f(CW\*(C`$r\->lookup_uri\*(C'\fR for further discussion. .ie n .SS """lookup_uri""" .el .SS \f(CWlookup_uri\fP .IX Subsection "lookup_uri" Create a sub request from the given URI. This sub request can be inspected to find information about the requested URI. .PP .Vb 2 \& $ret = $r\->lookup_uri($new_uri); \& $ret = $r\->lookup_uri($new_uri, $next_filter); .Ve .ie n .IP "obj: $r ( ""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 "arg1: $new_uri ( string )" 4 .el .IP "arg1: \f(CW$new_uri\fR ( string )" 4 .IX Item "arg1: $new_uri ( string )" The URI to lookup .ie n .IP "opt arg2: $next_filter ( ""Apache2::Filter object"" )" 4 .el .IP "opt arg2: \f(CW$next_filter\fR ( \f(CWApache2::Filter object\fR )" 4 .IX Item "opt arg2: $next_filter ( Apache2::Filter object )" The first filter the subrequest should pass the data through. If not specified it defaults to the first connection output filter for the main request \&\f(CW\*(C`$r\->proto_output_filters\*(C'\fR. So if the subrequest sends any output it will be filtered only once. If for example you desire to apply the main request's output filters to the sub-request output as well pass \&\f(CW\*(C`$r\->output_filters\*(C'\fR as an argument. .ie n .IP "ret: $ret ( ""Apache2::SubRequest object"" )" 4 .el .IP "ret: \f(CW$ret\fR ( \f(CWApache2::SubRequest object\fR )" 4 .IX Item "ret: $ret ( Apache2::SubRequest object )" The sub request record .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP Here is an example of a simple subrequest which serves uri \&\fI/new_uri\fR: .PP .Vb 2 \& sub handler { \& my $r = shift; \& \& my $subr = $r\->lookup_uri("/new_uri"); \& $subr\->run; \& \& return Apache2::Const::OK; \& } .Ve .PP If let's say you have three request output filters registered to run for the main request: .PP .Vb 3 \& PerlOutputFilterHandler MyApache2::SubReqExample::filterA \& PerlOutputFilterHandler MyApache2::SubReqExample::filterB \& PerlOutputFilterHandler MyApache2::SubReqExample::filterC .Ve .PP and you wish to run them all, the code needs to become: .PP .Vb 1 \& my $subr = $r\->lookup_uri("/new_uri", $r\->output_filters); .Ve .PP and if you wish to run them all, but the first one (\f(CW\*(C`filterA\*(C'\fR), the code needs to be adjusted to be: .PP .Vb 1 \& my $subr = $r\->lookup_uri("/new_uri", $r\->output_filters\->next); .Ve .ie n .SS """run""" .el .SS \f(CWrun\fP .IX Subsection "run" Run a sub-request .PP .Vb 1 \& $rc = $subr\->run(); .Ve .ie n .IP "obj: $subr ( ""Apache2::RequestRec object"" )" 4 .el .IP "obj: \f(CW$subr\fR ( \f(CWApache2::RequestRec object\fR )" 4 .IX Item "obj: $subr ( Apache2::RequestRec object )" The sub-request (e.g. returned by \f(CW\*(C`lookup_uri\*(C'\fR) .ie n .IP "ret: $rc ( integer )" 4 .el .IP "ret: \f(CW$rc\fR ( integer )" 4 .IX Item "ret: $rc ( integer )" The return code of the handler (\f(CW\*(C`Apache2::Const::OK\*(C'\fR, \f(CW\*(C`Apache2::Const::DECLINED\*(C'\fR, etc.) .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .SH "Unsupported API" .IX Header "Unsupported API" \&\f(CW\*(C`Apache2::SubRequest\*(C'\fR also provides auto-generated Perl interface for a few other methods which aren't tested at the moment and therefore their API is a subject to change. These methods will be finalized later as a need arises. If you want to rely on any of the following methods please contact the the mod_perl development mailing list so we can help each other take the steps necessary to shift the method to an officially supported API. .ie n .SS """internal_fast_redirect""" .el .SS \f(CWinternal_fast_redirect\fP .IX Subsection "internal_fast_redirect" META: Autogenerated \- needs to be reviewed/completed .PP Redirect the current request to a sub_req, merging the pools .PP .Vb 1 \& $r\->internal_fast_redirect($sub_req); .Ve .ie n .IP "obj: $r ( ""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 "arg1: $sub_req ( string )" 4 .el .IP "arg1: \f(CW$sub_req\fR ( string )" 4 .IX Item "arg1: $sub_req ( string )" A subrequest created from this request .IP "ret: no return value" 4 .IX Item "ret: no return value" .PD 0 .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PD .PP META: httpd\-2.0/modules/http/http_request.c declares this function as: .PP .Vb 1 \& /* XXX: Is this function is so bogus and fragile that we deep\-6 it? */ .Ve .PP do we really want to expose it to mod_perl users? .ie n .SS """lookup_dirent""" .el .SS \f(CWlookup_dirent\fP .IX Subsection "lookup_dirent" META: Autogenerated \- needs to be reviewed/completed .PP Create a sub request for the given apr_dir_read result. This sub request can be inspected to find information about the requested file .PP .Vb 3 \& $lr = $r\->lookup_dirent($finfo); \& $lr = $r\->lookup_dirent($finfo, $subtype); \& $lr = $r\->lookup_dirent($finfo, $subtype, $next_filter); .Ve .ie n .IP "obj: $r ( ""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 "arg1: $finfo ( ""APR::Finfo object"" )" 4 .el .IP "arg1: \f(CW$finfo\fR ( \f(CWAPR::Finfo object\fR )" 4 .IX Item "arg1: $finfo ( APR::Finfo object )" The apr_dir_read result to lookup .ie n .IP "arg2: $subtype ( integer )" 4 .el .IP "arg2: \f(CW$subtype\fR ( integer )" 4 .IX Item "arg2: $subtype ( integer )" What type of subrequest to perform, one of; .Sp .Vb 2 \& Apache2::SUBREQ_NO_ARGS ignore r\->args and r\->path_info \& Apache2::SUBREQ_MERGE_ARGS merge r\->args and r\->path_info .Ve .ie n .IP "arg3: $next_filter ( integer )" 4 .el .IP "arg3: \f(CW$next_filter\fR ( integer )" 4 .IX Item "arg3: $next_filter ( integer )" The first filter the sub_request should use. If this is NULL, it defaults to the first filter for the main request .ie n .IP "ret: $lr ( ""Apache2::RequestRec object"" )" 4 .el .IP "ret: \f(CW$lr\fR ( \f(CWApache2::RequestRec object\fR )" 4 .IX Item "ret: $lr ( Apache2::RequestRec object )" The new request record .IP "since: 2.0.00" 4 .IX Item "since: 2.0.00" .PP META: where do we take the apr_dir_read result from? .SH "See Also" .IX Header "See Also" mod_perl 2.0 documentation. .SH Copyright .IX Header "Copyright" mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0. .SH Authors .IX Header "Authors" The mod_perl development team and numerous contributors.