Apache::SubRequest - Perl API for Apache subrequests |
Apache::SubRequest - Perl API for Apache subrequests
use Apache::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; # optional $subr->DESTROY;
Apache::SubRequest
contains API for creating and running of Apache
sub-requests.
Apache::SubRequest
is a sub-class of Apache::RequestRec
object|docs::2.0::api::Apache::RequestRec>
.
Apache::SubRequest
provides the following functions and/or methods:
DESTROY
Free the memory associated with a sub request
$subr->DESTROY();
$subr
( Apache::SubRequest
object|docs::2.0::api::Apache::SubRequest/Description>
)This method will be called automatically when $subr
goes out of
scope, so there is no need to call it explicitly, unless you want to
free the memory earlier than that (for example if you run several
subrequests).
internal_redirect
Redirect the current request to some other uri internally
$r->internal_redirect($new_uri);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)$new_uri
( string )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 Apache::OK
. The
client will be unaware the a different request was served to her
behind the scenes.
internal_redirect_handler
Identical to internal_redirect|/C_internal_redirect_
, plus
automatically sets
$r->content_type|docs::2.0::api::Apache::RequestRec/C_content_type_
is of the sub-request to be the same as of the main request, if
$r->handler|docs::2.0::api::Apache::RequestRec/C_handler_
is
true.
$r->internal_redirect_handler($new_uri);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)$new_uri
( string )This function is designed for things like actions or CGI scripts, when
using AddHandler
, and you want to preserve the content type across
an internal redirect.
lookup_file
Create a subrequest for the given file. This sub request can be inspected to find information about the requested file
$ret = $r->lookup_file($new_file); $ret = $r->lookup_file($new_file, $next_filter);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)$new_file
( string )$next_filter
( Apache::Filter|docs::2.0::api::Apache::Filter
)$r->lookup_uri|/C_lookup_uri_
for details.
$ret
( Apache::SubRequest
object|docs::2.0::api::Apache::SubRequest/Description>
)See $r->lookup_uri|/C_lookup_uri_
for further discussion.
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
$ret = $r->lookup_method_uri($method, $new_uri); $ret = $r->lookup_method_uri($method, $new_uri, $next_filter);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)$method
( string )"GET"
)
$new_uri
( string )$next_filter
( Apache::Filter object|docs::2.0::api::Apache::Filter
)$r->lookup_uri|/C_lookup_uri_
for details.
$ret
( Apache::SubRequest
object|docs::2.0::api::Apache::SubRequest/Description>
)See $r->lookup_uri|/C_lookup_uri_
for further discussion.
lookup_uri
Create a sub request from the given URI. This sub request can be inspected to find information about the requested URI.
$ret = $r->lookup_uri($new_uri); $ret = $r->lookup_uri($new_uri, $next_filter);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)$new_uri
( string )$next_filter
( Apache::Filter object|docs::2.0::api::Apache::Filter
)$r->proto_output_filters|docs::2.0::api::Apache::RequestRec/C_proto_output_filters_
. 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
$r->output_filters|docs::2.0::api::Apache::RequestRec/C_output_filters_
as an argument.
$ret
( Apache::SubRequest
object|docs::2.0::api::Apache::SubRequest/Description>
)Here is an example of a simple subrequest which serves uri /new_uri:
sub handler { my $r = shift;
my $subr = $r->lookup_uri("/new_uri"); $sub->run;
return Apache::OK; }
If let's say you have three request output filters registered to run for the main request:
PerlOutputFilterHandler MyApache::SubReqExample::filterA PerlOutputFilterHandler MyApache::SubReqExample::filterB PerlOutputFilterHandler MyApache::SubReqExample::filterC
and you wish to run them all, the code needs to become:
my $subr = $r->lookup_uri("/new_uri", $r->output_filters);
and if you wish to run them all, but the first one (filterA
), the
code needs to be adjusted to be:
my $subr = $r->lookup_uri("/new_uri", $r->output_filters->next);
run
Run a sub-request
$rc = $subr->run();
$subr
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)lookup_uri|/C_lookup_uri_
)
$rc
( integer )Apache::OK
, Apache::DECLINED
,
etc.)
Apache::SubRequest
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.
internal_fast_redirect
META: Autogenerated - needs to be reviewed/completed
Redirect the current request to a sub_req, merging the pools
$r->internal_fast_redirect($sub_req);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)$sub_req
( string )META: httpd-2.0/modules/http/http_request.c declares this function as:
/* XXX: Is this function is so bogus and fragile that we deep-6 it? */
do we really want to expose it to mod_perl users?
lookup_dirent
META: Autogenerated - needs to be reviewed/completed
Create a sub request for the given apr_dir_read result. This sub request can be inspected to find information about the requested file
$lr = $r->lookup_dirent($finfo); $lr = $r->lookup_dirent($finfo, $subtype); $lr = $r->lookup_dirent($finfo, $subtype, $next_filter);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)$finfo
( APR::Finfo object|docs::2.0::api::APR::Finfo
)$subtype
( integer )Apache::SUBREQ_NO_ARGS ignore r->args and r->path_info Apache::SUBREQ_MERGE_ARGS merge r->args and r->path_info
$next_filter
( integer )$lr
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec
)META: where do we take the apr_dir_read result from?
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
The mod_perl development team and numerous contributors.
Apache::SubRequest - Perl API for Apache subrequests |