|
Apache::Response - Perl API for Apache HTTP request response methods |
custom_responsemake_etagmeets_conditionsrationalize_mtimesend_cgi_headerset_content_lengthset_etagset_keepaliveset_last_modifiedupdate_mtime
Apache::Response - Perl API for Apache HTTP request response methods
use Apache::Response ();
$r->custom_response(Apache::FORBIDDEN, "No Entry today");
$etag = $r->make_etag($force_weak); $r->set_etag(); $status = $r->meets_conditions();
$mtime_rat = $r->rationalize_mtime($mtime); $r->set_last_modified($mtime); $r->update_mtime($mtime);
$r->send_cgi_header($buffer);
$r->set_content_length($length);
$ret = $r->set_keepalive();
Apache::Response provides the Apache request object utilities API for dealing
with HTTP response generation process.
Apache::Response provides the following functions and/or methods:
custom_responseInstall a custom response handler for a given status
$r->custom_response($status, $string);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$status ( Apache::Const
constant|docs::2.0::api::Apache::Const> )Apache::AUTH_REQUIRED)
$string (string)custom_response() doesn't alter the response code, but is used to
replace the standard response body. For example, here is how to change
the response body for the access handler failure:
package MyApache::MyShop;
use Apache::Response ();
use Apache::Const -compile => qw(FORBIDDEN OK);
sub access {
my $r = shift;
if (MyApache::MyShop::tired_squirrels()) {
$r->custom_response(Apache::FORBIDDEN,
"It's siesta time, please try later");
return Apache::FORBIDDEN;
}
return Apache::OK;
}
...
# httpd.conf
PerlModule MyApache::MyShop
<Location /TestAPI__custom_response>
AuthName dummy
AuthType none
PerlAccessHandler MyApache::MyShop::access
PerlResponseHandler MyApache::MyShop::response
</Location>
When squirrels can't run any more, the handler will return 403, with the custom message:
It's siesta time, please try later
make_etagConstruct an entity tag from the resource information. If it's a real file, build in some of the file characteristics.
$etag = $r->make_etag($force_weak);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$force_weak (number)$etag (string)
meets_conditionsImplements condition GET rules for HTTP/1.1 specification. This
function inspects the client headers and determines if the response
fulfills the specified requirements.
$status = $r->meets_conditions();
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$status ( Apache::Const
status constant|docs::2.0::api::Apache::Const> )Apache::OK if the response fulfills the condition GET
rules. Otherwise some other status code (which should be returned to
Apache).
Refer to the Generating Correct HTTP Headers document for an indepth discussion of this method.
rationalize_mtimeReturn the latest rational time from a request/mtime pair.
$mtime_rat = $r->rationalize_mtime($mtime);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$mtime (number)$mtime_rat (number)
send_cgi_headerParse the header
$r->send_cgi_header($buffer);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$buffer (string)This method is really for back-compatibility with mod_perl 1.0. It's very inefficient to send headers this way, because of the parsing overhead.
If there is a response body following the headers it'll be handled too
(as if it was sent via
print()|docs::2.0::api::Apache::RequestIO::C_print_/).
Notice that if only HTTP headers are included they won't be sent until some body is sent (again the ``send'' part is retained from the mod_perl 1.0 method).
set_content_lengthSet the content length for this request.
$r->set_content_length($length);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$length (integer)
set_etagSet the E-tag outgoing header
$r->set_etag();
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )
set_keepaliveSet the keepalive status for this request
$ret = $r->set_keepalive();
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$ret ( boolean )It's called by ap_http_header_filter(). For the complete
complicated logic implemented by this method see
httpd-2.0/server/http_protocol.c.
set_last_modifiedsets the Last-Modified response header field to the value of the
mtime field in the request structure -- rationalized to keep it from
being in the future.
$r->set_last_modified($mtime);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$mtime ( time in microseconds )$mtime argument is passed,
$r->update_mtime will be first run with that
argument.
update_mtimeSet the
$r->mtime|docs::2.0::api::Apache::RequestRec/C_mtime_ field
to the specified value if it's later than what's already there.
$r->update_mtime($mtime);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$mtime ( time in microseconds )See also: $r->set_last_modified.
Apache::Response 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.
send_error_responseSend an ``error'' response back to client. It is used for any response that can be generated by the server from the request record. This includes all 204 (no content), 3xx (redirect), 4xx (client error), and 5xx (server error) messages that have not been redirected to another handler via the ErrorDocument feature.
$r->send_error_response($recursive_error);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$recursive_error ( boolean )ErrorDocument to handle some other error. In that
case, we print the default report for the first thing that went wrong,
and more briefly report on the problem with the ErrorDocument.
META: it's really an internal Apache method, I'm not quite sure how can it be used externally.
send_mmapMETA: Autogenerated - needs to be reviewed/completed
Send an MMAP'ed file to the client
$ret = $r->send_mmap($mm, $offset, $length);
$r
( Apache::RequestRec object|docs::2.0::api::Apache::RequestRec )$mm (APR::Mmap|docs::2.0::api::APR::Mmap)$offset (number)$length (integer)$ret (integer)META: requires a working APR::Mmap, which is not supported at the moment.
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::Response - Perl API for Apache HTTP request response methods |