NAME
Apache - Perl interface to the Apache server API
SYNOPSIS
use Apache ();
DESCRIPTION
This module provides a Perl interface the Apache API. It is here
mainly for mmooddppeerrll, but may be used for other Apache modules that wish
to embed a Perl interpreter. We suggest that you also consult thedescription of the Apache C API at http://www.apache.org/docs/.
TTHHEE RREEQQUUEESSTT OOBBJJEECCTT The request object holds all the information that the server needs toservice a request. Apache PPeerrll**HHaannddlleerrs will be given a reference to
the request object as parameter and may choose to update or use it in various ways. Most of the methods described below obtain information from or update the request object. The perl version of the request object will be blessed into the AAppaacchhee package, it is really a "requestrec*" in disguise.Apache->request([$r])
The Apache->request method will return a reference to the request
object. PPeerrll**HHaannddlleerrs can obtain a reference to the request object when it is passed to them via @. However, scripts that run under AAppaacchhee::::RReeggiissttrryy, for example, need a way to access the request object. AAppaacchhee::::RReeggiissttrryy will make a request object available to these scripts by passing an object reference to"Apache->request($r)". If handlers use modules such as CCGGII::::AAppaacchhee
that need to access "Apache->request", they too should do this
(e.g. AAppaacchhee::::SSttaattuuss).$r->asstring
Returns a string representation of the request object. Mainly use-
ful for debugging.$r->main
If the current request is a sub-request, this method returns a
blessed reference to the main request structure. If the current request is the main request, then this method returns "undef".$r->prev
This method returns a blessed reference to the previous (internal) request structure or "undef" if there is no previous request.$r->next
This method returns a blessed reference to the next (internal) request structure or "undef" if there is no next request.$r->last
This method returns a blessed reference to the last (internal) request structure. Handy for logging modules.$r->ismain
Returns true if the current request object is for the main request.(Should give the same result as "!$r->main", but will be more effi-
cient.)$r->isinitialreq
Returns true if the current request is the first internal request,returns false if the request is a sub-request or internal redirect.
$r->allowed($bitmask)
Get or set the allowed methods bitmask. This allowed bitmask should be set whenever a 405 (method not allowed) or 501 (method not implemented) answer is returned. The bit corresponding to the method number should be et.unless ($r->methodnumber == MGET) {
$r->allowed($r->allowed | (1<
return HTTPMETHODNOTALLOWED; } SSUUBB RREEQQUUEESSTTSS Apache provides a sub-request mechanism to lookup a uri or filename,
performing all access checks, etc., without actually running the response phase of the given request. Notice, we have dropped the "subreq" prefix here. The "requestrec*" returned by the lookup methods is blessed into the AAppaacchhee::::SSuubbRReeqquueesstt class. This way,"destroysubrequest()" is called automatically during "Apache::SubRe-
quest->DESTROY" when the object goes out of scope. The AAppaacchhee::::SSuubbRRee-
qquueesstt class inherits all the methods from the AAppaacchhee class.$r->lookupuri($uri)
my $subr = $r->lookupuri($uri);
my $filename = $subr->filename;
unless(-e $filename) {
warn "can't stat $filename!\n";
}$r->lookupfile($filename)
my $subr = $r->lookupfile($filename);
$subr->run
if($subr->run != OK) {
$subr->logerror("something went wrong!");
} CCLLIIEENNTT RREEQQUUEESSTT PPAARRAAMMEETTEERRSS In this section we will take a look at various methods that can be usedto retrieve the request parameters sent from the client. In the fol-
lowing examples, $$rr is a request object blessed into the AAppaacchhee class,
obtained by the first parameter passed to a handler subroutine orApache->request
$r->method( [$meth] )
The $r->method method will return the request method. It will be a
string such as "GET", "HEAD" or "POST". Passing an argument will set the method, mainly used for internal redirects.$r->methodnumber( [$num] )
The $r->methodnumber method will return the request method number.
The method numbers are defined by the MGET, MPOST,... constants available from the AAppaacchhee::::CCoonnssttaannttss module. Passing an argument will set the methodnumber, mainly used for internal redirects and testing authorization restriction masks.$r->bytessent
The number of bytes sent to the client, handy for logging, etc.$r->therequest
The request line sent by the client, handy for logging, etc.$r->proxyreq
Returns true if the request is proxy http. Mainly used during the filename translation stage of the request, which may be handled by a "PerlTransHandler".$r->headeronly
Returns true if the client is asking for headers only, e.g. if the request method was HHEEAADD.$r->protocol
The $r->protocol method will return a string identifying the proto-
col that the client speaks. Typical values will be "HTTP/1.0" or "HTTP/1.1".$r->hostname
Returns the server host name, as set by full URI or Host: header.$r->requesttime
Returns the time that the request was made. The time is the local unix time in seconds since the epoch.$r->uri( [$uri] )
The $r->uri method will return the requested URI minus optional
query string, optionally changing it with the first argument.$r->filename( [$filename] )
The $r->filename method will return the result of the URI -> file-
name translation, optionally changing it with the first argument if you happen to be doing the translation.$r->location
The $r->location method will return the path of the
tion from which the current "Perl*Handler" is being called.sec- $r->pathinfo( [$pathinfo] )
The $r->pathinfo method will return what is left in the path after
the URI -> filename translation, optionally changing it with the
first argument if you happen to be doing the translation.$r->args( [$querystring] )
The $r->args method will return the contents of the URI query
string. When called in a scalar context, the entire string is returned. When called in a list context, a list of parsed key => value pairs are returned, i.e. it can be used like this:$query = $r->args;
%in = $r->args;
$r->args can also be used to set the query string. This can be use-
ful when redirecting a POST request.$r->headersin
The $r->headersin method will return a %hash of client request
headers. This can be used to initialize a perl hash, or one coulduse the $r->headerin() method (described below) to retrieve a spe-
cific header value directly.Will return a HASH reference blessed into the Apache::Table class
when called in a scalar context with no "key" argument. Thisrequires Apache::Table.
$r->headerin( $headername, [$value] )
Return the value of a client header. Can be used like this:$ct = $r->headerin("Content-type");
$r->headerin($key, $val); #set the value of header '$key'
$r->content
The $r->content method will return the entity body read from the
client, but only if the request content type is "applica-
tion/x-www-form-urlencoded". When called in a scalar context, the
entire string is returned. When called in a list context, a listof parsed key => value pairs are returned. *NOTE*: you can only
ask for this once, as the entire body is read from the client.$r->read($buf, $bytestoread, [$offset])
This method is used to read data from the client, looping until itgets all of $bytestoread or a timeout happens.
An offset may be specified to place the read data at some other place than the beginning of the string. In addition, this method sets a timeout before reading with"$r->softtimeout".
$r->getremotehost
Lookup the client's DNS hostname. If the configuration directiveHHoossttNNaammeeLLooookkuuppss is set to off, this returns the dotted decimal rep-
resentation of the client's IP address instead. Might return undef if the hostname is not known.$r->getremotelogname
Lookup the remote user's system name. Might return undef if theremote system is not running an RFC 1413 server or if the configu-
ration directive IIddeennttiittyyCChheecckk is not turned on.More information about the client can be obtained from the AAppaacchhee::::CCoonn-
nneeccttiioonn object, as described below.$c = $r->connection
The $r->connection method will return a reference to the request
connection object (blessed into the AAppaacchhee::::CCoonnnneeccttiioonn package). This is really a "connrec*" in disguise. The following methods can be used on the connection object:$c->remotehost
If the configuration directive HHoossttNNaammeeLLooookkuuppss is set to on:then the first time "$r->getremotehost" is called the server
does a DNS lookup to get the remote client's host name. Theresult is cached in "$c->remotehost" then returned. If the
server was unable to resolve the remote client's host name thiswill be set to "". Subsequent calls to "$r->getremotehost"
return this cached value. If the configuration directive HHoossttNNaammeeLLooookkuuppss is set to off:calls to "$r->getremotehost" return a string that contains
the dotted decimal representation of the remote client's IP address. However this string is not cached, and"$c->remotehost" is undefined. So, it's best to to call
"$r->getremotehost" instead of directly accessing this vari-
able.$c->remoteip
The dotted decimal representation of the remote client's IP address. This is set by the server when the connection record is created so is always defined. You can also set this value by providing an argument to it. This is helpful if your server is behind a squid acceleratorproxy which adds a X-Forwarded-For header.
$c->localaddr
A packed SOCKADDRIN in the same format as returned by "packsockaddrin" in Socket, containing the port and address on the local host that the remote client is connected to. This is set by the server when the connection record is created so it is always defined.$c->remoteaddr
A packed SOCKADDRIN in the same format as returned by "packsockaddrin" in Socket, containing the port and address on the remote host that the server is connected to. This is set by the server when the connection record is created so it is always defined. Among other things, this can be used, together with"$c->localaddr", to perform RFC1413 ident lookups on the
remote client even when the configuration directive IIddeennttiittyy-
CChheecckk is turned off. Can be used like: use Net::Ident qw (lookupFromInAddr); ...my $remoteuser = lookupFromInAddr ($c->localaddr,
$c->remoteaddr, 2);
Note that the lookupFromInAddr interface does not currently exist in the NNeett::::IIddeenntt module, but the author is planning on adding it soon.$c->remotelogname
If the configuration directive IIddeennttiittyyCChheecckk is set to on:then the first time "$r->getremotelogname" is called the
server does an RFC 1413 (ident) lookup to get the remote users system name. Generally for UNI* systems this is their login.The result is cached in "$c->remotelogname" then returned.
Subsequent calls to "$r->getremotehost" return the cached
value. If the configuration directive IIddeennttiittyyCChheecckk is set to off:then "$r->getremotelogname" does nothing and "$c->remotelog-
name" is always undefined.$c->user( [$user] )
If an authentication check was successful, the authentication handler caches the user name here. Sets the user name to the optional first argument.$c->authtype
Returns the authentication scheme that successfully authenti-
cate "$c->user", if any.
$c->aborted
Returns true if the client stopped talking to us.$c->fileno( [$direction] )
Returns the client file descriptor. If $direction is 0, the
input fd is returned. If $direction is not null or ommitted,
the output fd is returned. This can be used to detect client disconnect without doing any I/O, e.g. using IO::Select. SSEERRVVEERR CCOONNFFIIGGUURRAATTIIOONN IINNFFOORRMMAATTIIOONNThe following methods are used to obtain information from server con-
figuration and access control files.$r->dirconfig( $key )
Returns the value of a per-directory variable specified by the
"PerlSetVar" directive.#
# PerlSetVar Key Value
#
my $val = $r->dirconfig('Key');
Keys are case-insensitive.
Will return a HASH reference blessed into the Apache::Table class
when called in a scalar context with no "key" argument. SeeApache::Table.
$r->dirconfig->get( $key )
Returns the value of a per-directory array variable specified by
the "PerlAddVar" directive.#
# PerlAddVar Key Value1
# PerlAddVar Key Value2
#
my @val = $r->dirconfig->get('Key');
Alternatively in your code you can extend the setting with:$r->dirconfig->add(Key => 'Value3');
Keys are case-insensitive.
Will return a HASH reference blessed into the Apache::Table class
when called in a scalar context with no "key" argument. SeeApache::Table.
$r->requires
Returns an array reference of hash references, containing informa-
tion related to the rreeqquuiirree directive. This is normally used foraccess control, see Apache::AuthzAge for an example.
$r->authtype
Returns a reference to the current value of the per directory con-
figuration directive AAuutthhTTyyppee. Normally this would be set to "Basic" to use the basic authentication scheme defined in RFC 1945,Hypertext Transfer Protocol - HTTP/1.0. However, you could set to
something else and implement your own authentication scheme.$r->authname
Returns a reference to the current value of the per directory con-
figuration directive AAuutthhNNaammee. The AuthName directive creates pro-
tection realm within the server document space. To quote RFC 1945"These realms allow the protected resources on a server to be par-
titioned into a set of protection spaces, each with its own authen-
tication scheme and/or authorization database." The client uses theroot URL of the server to determine which authentication creden-
tials to send with each HTTP request. These credentials are tagged with the name of the authentication realm that created them. Thenduring the authentication stage the server uses the current authen-
tication realm, from "$r->authname", to determine which set of
credentials to authenticate.$r->documentroot( [$docroot] )
When called with no argument, returns a reference to the current value of the per server configuration directive DDooccuummeennttRRoooott. Toquote the Apache server documentation, "Unless matched by a direc-
tive like Alias, the server appends the path from the requested URL to the document root to make the path to the document." This same value is passed to CGI scripts in the "DOCUMENTROOT" environment variable. You can also set this value by providing an argument to it. The following example dynamically sets the document root based on the request's "Host:" header: sub transhandler {my $r = shift;
my ($user) = ($r->headerin('Host') =~ /^[^\.]+/);
$r->documentroot("/home/$user/www");
return DECLINED; } PerlTransHandler transhandler$r->serverrootrelative( [$relativepath] )
If called without any arguments, this method returns the value ofthe currently-configured "ServerRoot" directory.
If a single argument is passed, it concatenates it with the value of "ServerRoot". For example here is how to get the path to the errorlog file under the server root:my $errorlog = $r->serverrootrelative("logs/errorlog");
See also the next item.Apache->serverrootrelative( [$relativepath] )
Same as the previous item, but this time it's used without a request object. This method is usually needed in a startup file. For example the following startup file modifies @INC to add a local directory with perl modules located under the server root and after that loads a module from that directory. BEGIN {use Apache():
use lib Apache->serverrootrelative("lib/myproject");
} use MyProject::Config ();$r->allowoptions
The "$r->allowoptions" method can be used for checking if it is OK
o u a el cit Te Apache::Options oue rvds h cn
stants to check against.if(!($r->allowoptions & OPTEXECCGI)) {
$r->logreason("Options ExecCGI is off in this directory",
$filename);
}$r->getserverport
Returns the port number on which the server is listening.$s = $r->server
Return a reference to the server info object (blessed into theAAppaacchhee::::SSeerrvveerr package). This is really a "serverrec*" in dis-
guise. The following methods can be used on the server object:$s = Apache->server
Same as above, but only available during server startup for use in "" sections, PPeerrllRReeqquuiirree or PPeerrllMMoodduullee. $s->serveradmin
Returns the mail address of the person responsible for this server.$s->serverhostname
Returns the hostname used by this server.$s->port
Returns the port that this servers listens too.$s->isvirtual
Returns true if this is a virtual server.$s->names
Returns the wild-carded names for ServerAlias servers.
$s->dirconfig( $key )
Alias for Apache::dirconfig.
$s->warn
Alias for Apache::warn.
$s->logerror
Alias for Apache::logerror.
$s->uid
Returns the numeric user id under which the server answers requests. This is the value of the User directive.$s->gid
Returns the numeric group id under which the server answers requests. This is the value of the Group directive.$s->loglevel
Get or set the value of the current LogLevel. This method is addedby the Apache::Log module, which needs to be pulled in.
use Apache::Log;
print "LogLevel = ", $s->loglevel;
$s->loglevel(Apache::Log::DEBUG);
If using Perl 5.005+, the following constants are defined (but not exported):Apache::Log::EMERG
Apache::Log::ALERT
Apache::Log::CRIT
Apache::Log::ERR
Apache::Log::WARNING
Apache::Log::NOTICE
Apache::Log::INFO
Apache::Log::DEBUG
$r->gethandlers( $hook )
Returns a reference to a list of handlers enabled for $hook. $hook
is a string representing the phase to handle. The returned list is a list of references to the handler subroutines.$list = $r->gethandlers( 'PerlHandler' );
$r->sethandlers( $hook, [\&handler, ... ] )
Sets the list if handlers to be called for $hook. $hook is a string
representing the phase to handle. The list of handlers is an anony-
mous array of code references to the handlers to install for this request phase. The special list "[ \&OK ]" can be used to disable a particular phase.$r->sethandlers( PerlLogHandler => [ \&myhandler1, \&myhandler2 ] );
$r->sethandlers( PerlAuthenHandler => [ \&OK ] );
$r->pushhandlers( $hook, \&handler )
Pushes a new handler to be called for $hook. $hook is a string rep-
resenting the phase to handle. The handler is a reference to a sub-
routine to install for this request phase. This handler will be called before any configured handlers.$r->pushhandlers( PerlHandler => \&footer);
$r->currentcallback
Returns the name of the handler currently being run. This method is most useful to PerlDispatchHandlers who wish to only take action for certain phases.if($r->currentcallback eq "PerlLogHandler") {
$r->warn("Logging request");
} SSEETTTTIINNGG UUPP TTHHEE RREESSPPOONNSSEE The following methods are used to set up and return the response backto the client. This typically involves setting up $r->status(), the
various content attributes and optionally some additional$r->headerout() calls before calling $r->sendhttpheader() which will
actually send the headers to the client. After this a typical applica-
tion will call the $r->print() method to send the response content to
the client.$r->sendhttpheader( [$contenttype] )
Send the response line and all headers to the client. Takes anoptional parameter indicating the content-type of the response,
i.e. 'text/html'.This method will create headers from the $r->contentxxx() and
$r->nocache() attributes (described below) and then append the
headers defined by $r->headerout (or $r->errheaderout if status
indicates an error).$r->getbasicauthpw
If the current request is protected by Basic authentication, this method will return OK. Otherwise, it will return a value that ought to be propagated back to the client (typicallyAUTHREQUIRED). The second return value will be the decoded pass-
word sent by the client.($ret, $sentpw) = $r->getbasicauthpw;
$r->notebasicauthfailure
Prior to requiring Basic authentication from the client, this method will set the outgoing HTTP headers asking the client to authenticate for the realm defined by the configuration directive "AuthName".$r->handler( [$meth] )
Set the handler for a request. Normally set by the configuration directive "AddHandler".$r->handler( "perl-script" );
$r->notes( $key, [$value] )
Return the value of a named entry in the Apache "notes" table, or
optionally set the value of a named entry. This table is used byApache modules to pass messages amongst themselves. Generally if
you are writing handlers in modperl you can use Perl variables for this.$r->notes("MYHANDLER" => OK);
$val = $r->notes("MYHANDLER");
Will return a HASH reference blessed into the Apache::Table class
when called in a scalar context with no "key" argument. Thisrequires Apache::Table.
$r->pnotes( $key, [$value] )
Like $r->notes, but takes any scalar as an value.
$r->pnotes("MYHANDLER" => [qw(one two)]);
my $val = $r->pnotes("MYHANDLER");
print $val->[0]; # prints "one"
Advantage over just using a Perl variable is that $r->pnotes gets
cleaned up after every request.$r->subprocessenv( $key, [$value] )
Return the value of a named entry in the Apache "subprocessenv"
table, or optionally set the value of a named entry. This table is used by modinclude. By setting some custom variables inside a perl handler it is possible to combine perl with modinclude nicely. If you say, e.g. in a PerlHeaderParserHandler$r->subprocessenv(MyLanguage => "de");
you can then write in your .shtml document:English
Deutsch
Sorry
Will return a HASH reference blessed into the Apache::Table class
when called in a scalar context with no "key" argument. Thisrequires Apache::Table.
$r->contenttype( [$newval] )
Get or set the content type being sent to the client. Content types are strings like "text/plain", "text/html" or "image/gif".This corresponds to the "Content-Type" header in the HTTP protocol.
Example of usage is:$previoustype = $r->contenttype;
$r->contenttype("text/plain");
$r->contentencoding( [$newval] )
Get or set the content encoding. Content encodings are string like"gzip" or "compress". This correspond to the "Content-Encoding"
header in the HTTP protocol.$r->contentlanguages( [$arrayref] )
Get or set the content languages. The content language correspondsto the "Content-Language" HTTP header and is an array reference
containing strings such as "en" or "no".$r->status( $integer )
Get or set the reply status for the client request. The AAppaacchhee::::CCoonnssttaannttss module provide mnemonic names for the status codes.$r->statusline( $string )
Get or set the response status line. The status line is a string like "200 Document follows" and it will take precedence over thevalue specified using the $r->status() described above.
$r->headersout
The $r->headersout method will return a %hash of server response
headers. This can be used to initialize a perl hash, or one coulduse the $r->headerout() method (described below) to retrieve or
set a specific header value directly.Will return a HASH reference blessed into the Apache::Table class
when called in a scalar context with no "key" argument. Thisrequires Apache::Table.
$r->headerout( $header, $value )
Change the value of a response header, or create a new one. Youshould not define any "Content-XXX" headers by calling this method,
because these headers use their own specific methods. Example of use:$r->headerout("WWW-Authenticate" => "Basic");
$val = $r->headerout($key);
$r->errheadersout
The $r->errheadersout method will return a %hash of server
response headers. This can be used to initialize a perl hash, orone could use the $r->errheaderout() method (described below) to
retrieve or set a specific header value directly. The difference between headersout and errheadersout is that thelatter are printed even on error, and persist across internal redi-
rects (so the headers printed for ErrorDocument handlers will have them).Will return a HASH reference blessed into the Apache::Table class
when called in a scalar context with no "key" argument. Thisrequires Apache::Table.
$r->errheaderout( $header, [$value] )
Change the value of an error response header, or create a new one. These headers are used if the status indicates an error.$r->errheaderout("Warning" => "Bad luck");
$val = $r->errheaderout($key);
$r->nocache( $boolean )
This is a flag that indicates that the data being returned is volatile and the client should be told not to cache it."$r->nocache(1)" adds the headers "Pragma: no-cache" and
"Cache-control: no-cache" to the reponse, therefore it must be
called before "$r->sendhttpheader".
$r->print( @list )
This method sends data to the client with "$r->writeclient", but
first sets a timeout before sending with "$r->softtimeout". This
method is called instead of CORE::print when you use print() in your modperl programs. This method treats scalar references specially. If an item in @list is a scalar reference, it will be dereferenced before printing. This is a performance optimization which prevents unneeded copying of large strings, and it is subtly different from Perl's standard print() behavior. Example:$foo = \"bar"; print($foo);
The result is "bar", not the "SCALAR(0xDEADBEEF)" you might have expected. If you really want the reference to be printed out, forceit into a scalar context by using "print(scalar($foo))".
$r->sendfd( $filehandle )
Send the contents of a file to the client. Can for instance be used like this:open(FILE, $r->filename) || return 404;
$r->sendfd(FILE);
close(FILE);$r->internalredirect( $newplace )
Redirect to a location in the server namespace without telling the client. For instance:$r->internalredirect("/home/sweet/home.html");
$r->internalredirecthandler( $newplace )
Same as internalredirect, but the handler from $r is preserved.
$r->customresponse($code, $uri)
This method provides a hook into the EErrrroorrDDooccuummeenntt mechanism, allowing you to configure a custom response for a given responsecode at request-time.
Example:use Apache::Constants ':common';
sub handler {my($r) = @;
if($thingsareok) {
return OK; }#
uri> #ErrorDocument 401 /error.html
#
$r->customresponse(AUTHREQUIRED, "/error.html");
#can send a string too
#
uri> #ErrorDocument 401 "sorry, go away"
#
#$r->customresponse(AUTHREQUIRED, "sorry, go away");
return AUTHREQUIRED; } SSEERRVVEERR CCOORREE FFUUNNCCTTIIOONNSS$r->softtimeout($message)
$r->hardtimeout($message)
$r->killtimeout
$r->resettimeout
(Documentation borrowed from httpmain.h) There are two functions which modules can call to trigger a timeout(with the per-virtual-server timeout duration); these are
hardtimeout and softtimeout. The difference between the two is what happens when the timeoutexpires (or earlier than that, if the client connection aborts) --
a softtimeout just puts the connection to the client in an "aborted" state, which will cause httpprotocol.c to stop trying totalk to the client, but otherwise allows the code to continue nor-
mally. hardtimeout(), by contrast, logs the request, and thenaborts it completely -- longjmp()ing out to the accept() loop in
httpmain. Any resources tied into the request resource pool will be cleaned up; everything that is not will leak. softtimeout() is recommended as a general rule, because it gives your code a chance to clean up. However, hardtimeout() may be the most convenient way of dealing with timeouts waiting for some external resource other than the client, if you can live with the restrictions. When a hard timeout is in scope, critical sections can be guardedwith blockalarms() and unblockalarms() -- these are declared in
alloc.c because they are most often used in conjunction with rou-
tines to allocate something or other, to make sure that the cleanup does get registered before any alarm is allowed to happen which might require it to be cleaned up; they * are, however, implemented in httpmain.c. killtimeout() will disarm either variety of timeout. resettimeout() resets the timeout in progress.$r->postconnection($coderef)
$r->registercleanup($coderef)
Register a cleanup function which is called just before $r->pool is
destroyed.$r->registercleanup(sub {
my $r = shift;
warn "registered cleanup called for ", $r->uri, "\n";
}); Cleanup functions registered in the parent process (before forking) will run once when the server is shut down:#PerlRequire startup.pl
warn "parent pid is $$\n";
Apache->server->registercleanup(sub { warn "server cleanup in $$\n"});
The postconnection method is simply an alias for registercleanup, as this method may be used to run code after the client connection is closed, which may not be a cleanup. CCGGII SSUUPPPPOORRTT We also provide some methods that make it easier to support the CGI type of interface.$r->sendcgiheader()
Take action on certain headers including Status:, Location: andContent-type: just as modcgi does, then calls
$r->sendhttpheader(). Example of use:
$r->sendcgiheader(<
Location: /foo/bar Content-type: text/html
EOT EERRRROORR LLOOGGGGIINNGG The following methods can be used to log errors.$r->logreason($message, $file)
The request failed, why?? Write a message to the server errorlog.$r->logreason("Because I felt like it", $r->filename);
$r->logerror($message)
Uh, oh. Write a message to the server errorlog.$r->logerror("Some text that goes in the errorlog");
$r->warn($message)
For pre-1.3 versions of apache, this is just an alias for
"logerror". With 1.3+ versions of apache, this message will only be send to the errorlog if LLooggLLeevveell is set to wwaarrnn or higher. UUTTIILLIITTYY FFUUNNCCTTIIOONNSSApache::unescapeurl($string)
$unescapedurl = Apache::unescapeurl($string)
Handy function for unescapes. Use this one for filenames/paths.Notice that the original $string is mangled in the process (because
the string part of PV shrinks, but the variable is not updated, to speed things up). Use unescapeurlinfo for the result of submitted form data.Apache::unescapeurlinfo($string)
Handy function for unescapes submitted form data. In opposite to unescapeurl it translates the plus sign to space.Apache::perlhook($hook)
Returns true if the specified callback hook is enabled: for (qw(Access Authen Authz ChildInit Cleanup Fixup HeaderParser Init Log Trans Type)) {print "$ hook enabled\n" if Apache::perlhook($);
} GGLLOOBBAALL VVAARRIIAABBLLEESS$Apache::Server::Starting
Set to true when the server is starting.$Apache::Server::ReStarting
Set to true when the server is starting.SEE ALSO
perl(1), Apache::Constants(3), Apache::Registry(3), Apache::Debug(3),
Apache::Options(3), CGI::Apache(3)
Apache C API notes at "http://www.apache.org/docs/"
AUTHORSPerl interface to the Apache C API written by Doug MacEachern with con-
tributions from Gisle Aas, Andreas Koenig, Eric Bartley, Rob Hartill, Gerald Richter, Salvador Ortiz and others.perl v5.8.6 2003-10-08 Apache(3)