libapa...esponse(3pm)
π libapa...esponse β the Perl API for Apache HTTP request response methods π
okay bestie, welcome to libapa...esponse(3pm), straight outta the User Contributed Perl Documentation corner of the internet π«Ά this is the page where Apache2::Response lives, and she is that girl: the utilities API that handles the whole HTTP response generation process for your Apache request object. no cap. β¨
πΈ NAME πΈ
Apache2::Response β the Perl API for Apache HTTP request response methods π
β¨ Synopsis β¨
like, here's the vibe at a glance, no notes:
use Apache2::Response ();
$r->custom_response(Apache2::Const::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();
π¦ Description π¦
Apache2::Response hands you the Apache request object utilities API for dealing with the HTTP response generation process. that's it, that's the whole job, and she does it flawlessly. π
π API π
Apache2::Response provides the following functions and/or methods:
π custom_response
Install a custom response handler for a given status π₯
$r->custom_response($status, $string);
- obj:
$r(Apache2::RequestRec object) β the current request π - arg1:
$status(Apache2::Const constant) β the status the custom response should be used for, like e.g.Apache2::Const::AUTH_REQUIRED - arg2:
$string(string) β the custom response to use. this can be a static string, or a URL, full or just the uri path (/foo/bar.txt). versatile queen π - ret: no return value
- since: 2.0.00
custom_response() doesn't alter the response code, but it is used to replace the standard response body. for example, here's how to change the response body for the access handler failure:
package MyApache2::MyShop;
use Apache2::Response ();
use Apache2::Const -compile => qw(FORBIDDEN OK);
sub access {
my $r = shift;
if (MyApache2::MyShop::tired_squirrels()) {
$r->custom_response(Apache2::Const::FORBIDDEN,
"It's siesta time, please try later");
return Apache2::Const::FORBIDDEN;
}
return Apache2::Const::OK;
}
...
# httpd.conf
PerlModule MyApache2::MyShop
<Location /TestAPI__custom_response>
AuthName dummy
AuthType none
PerlAccessHandler MyApache2::MyShop::access
PerlResponseHandler MyApache2::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_etag
Construct 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);
- obj:
$r(Apache2::RequestRec object) β the current request - arg1:
$force_weak(number) β force the entity tag to be weak β it could be modified again in as short an interval. lowkey fragile, we love that for her π - ret:
$etag(string) β the entity tag - since: 2.0.00
π« meets_conditions
Implements condition GET rules for the HTTP/1.1 specification. this function inspects the client headers and determines if the response fulfills the specified requirements. detective work, honestly π
$status = $r->meets_conditions();
- obj:
$r(Apache2::RequestRec object) β the current request - ret:
$status(Apache2::Const status constant) βApache2::Const::OKif the response fulfills the condition GET rules. otherwise some other status code (which should be returned to Apache). π - since: 2.0.00
refer to the Generating Correct HTTP Headers document for an indepth discussion of this method. iykyk π
π§ rationalize_mtime
Return the latest rational time from a request/mtime pair. so reasonable of her. π
$mtime_rat = $r->rationalize_mtime($mtime);
- obj:
$r(Apache2::RequestRec object) β the current request - arg1:
$mtime( time in seconds ) β the last modified time - ret:
$mtime_rat( time in seconds ) β the latest rational time from a request/mtime pair. Mtime is returned unless it's in the future, in which case we return the current time. no time travelers allowed, periodt β° - since: 2.0.00
πΈ send_cgi_header
Parse the header π«Ά
$r->send_cgi_header($buffer);
- obj:
$r(Apache2::RequestRec object) - arg1:
$buffer(string) β headers and optionally a response body - ret: no return value
- since: 2.0.00
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. bestie, it's giving "we keep it around for the lore" π
if there is a response body following the headers it'll be handled too (as if it was sent via 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). so she waits. main character patience. β¨
π set_content_length
Set the content length for this request.
$r->set_content_length($length);
- obj:
$r(Apache2::RequestRec object) β the current request - arg1:
$length(integer) β the new content length - ret: no return value
- since: 2.0.00
β set_etag
Set the E-tag outgoing header β¨
$r->set_etag();
- obj:
$r(Apache2::RequestRec object) - ret: no return value
- since: 2.0.00
π₯ set_keepalive
Set the keepalive status for this request π
$ret = $r->set_keepalive();
- obj:
$r(Apache2::RequestRec object) β the current request - ret:
$ret( boolean ) β true if keepalive can be set, false otherwise - since: 2.0.00
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. it's a lot. she said "go read the source, babe" π
π
set_last_modified
sets 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. so no future dates, obviously, we're not messy. π
$r->set_last_modified($mtime);
- obj:
$r(Apache2::RequestRec object) - opt arg1:
$mtime( time in seconds ) β if the$mtimeargument is passed,$r->update_mtimewill be first run with that argument. - ret: no return value
- since: 2.0.00
π update_mtime
Set the $r->mtime field to the specified value if it's later than what's already there. only if it's later, bestie β she's not downgrading herself. π
$r->update_mtime($mtime);
- obj:
$r(Apache2::RequestRec object) β the current request - arg1:
$mtime( time in seconds ) - ret: no return value
- since: 2.0.00
see also: $r->set_last_modified. π«Ά
π Unsupported API π
Apache2::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. β¨ (yes, the double "the the" is in there, i'm keeping the relic exactly as it is, don't come for me π)
π«§ send_error_response
Send 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. the whole drama spectrum, honestly. π
$r->send_error_response($recursive_error);
- obj:
$r(Apache2::RequestRec object) β the current request - arg1:
$recursive_error( boolean ) β the error status in case we get an error in the process of trying to deal with anErrorDocumentto 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 theErrorDocument. error on error on error, it's giving inception π - ret: no return value
- since: 2.0.00
META: it's really an internal Apache method, I'm not quite sure how can it be used externally. π
π§΅ send_mmap
META: Autogenerated - needs to be reviewed/completed
Send an MMAP'ed file to the client π₯
$ret = $r->send_mmap($mm, $offset, $length);
- obj:
$r(Apache2::RequestRec object) β the current request - arg1:
$mm(APR::Mmap) β the MMAP'ed file to send - arg2:
$offset(number) β the offset into the MMAP to start sending - arg3:
$length(integer) β the amount of data to send - ret:
$ret(integer) β the number of bytes sent - since: 2.0.00
META: requires a working APR::Mmap, which is not supported at the moment. π
π See Also π
mod_perl 2.0 documentation. go read it, bestie, it's lore π
π Copyright π
mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 2.0.
π Authors π
The mod_perl development team and numerous contributors. π«Ά icons, all of them.
okay that's the whole page, you ate that π
built from perl v5.42.3, dated 2026-08-20 β that's the version and date tea, bestie, sip responsibly πβ¨
π¦ where this page comes from
- ubuntu stonking: libapache2-mod-perl2 2.0.13-2build3 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms