.rn '' }`
''' $RCSfile$$Revision$$Date$
'''
''' $Log$
'''
.de Sh
.br
.if t .Sp
.ne 5
.PP
\fB\\$1\fR
.PP
..
.de Sp
.if t .sp .5v
.if n .sp
..
.de Ip
.br
.ie \\n(.$>=3 .ne \\$3
.el .ne 3
.IP "\\$1" \\$2
..
.de Vb
.ft CW
.nf
.ne \\$1
..
.de Ve
.ft R

.fi
..
'''
'''
'''     Set up \*(-- to give an unbreakable dash;
'''     string Tr holds user defined translation string.
'''     Bell System Logo is used as a dummy character.
'''
.tr \(*W-|\(bv\*(Tr
.ie n \{\
.ds -- \(*W-
.ds PI pi
.if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch
.if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch
.ds L" ""
.ds R" ""
'''   \*(M", \*(S", \*(N" and \*(T" are the equivalent of
'''   \*(L" and \*(R", except that they are used on ".xx" lines,
'''   such as .IP and .SH, which do another additional levels of
'''   double-quote interpretation
.ds M" """
.ds S" """
.ds N" """""
.ds T" """""
.ds L' '
.ds R' '
.ds M' '
.ds S' '
.ds N' '
.ds T' '
'br\}
.el\{\
.ds -- \(em\|
.tr \*(Tr
.ds L" ``
.ds R" ''
.ds M" ``
.ds S" ''
.ds N" ``
.ds T" ''
.ds L' `
.ds R' '
.ds M' `
.ds S' '
.ds N' `
.ds T' '
.ds PI \(*p
'br\}
.\"	If the F register is turned on, we'll generate
.\"	index entries out stderr for the following things:
.\"		TH	Title 
.\"		SH	Header
.\"		Sh	Subsection 
.\"		Ip	Item
.\"		X<>	Xref  (embedded
.\"	Of course, you have to process the output yourself
.\"	in some meaninful fashion.
.if \nF \{
.de IX
.tm Index:\\$1\t\\n%\t"\\$2"
..
.nr % 0
.rr F
.\}
.TH Apache 3 "perl 5.005, patch 03" "12/Dec/2000" "User Contributed Perl Documentation"
.UC
.if n .hy 0
.if n .na
.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
.de CQ          \" put $1 in typewriter font
.ft CW
'if n "\c
'if t \\&\\$1\c
'if n \\&\\$1\c
'if n \&"
\\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
'.ft R
..
.\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
.	\" AM - accent mark definitions
.bd B 3
.	\" fudge factors for nroff and troff
.if n \{\
.	ds #H 0
.	ds #V .8m
.	ds #F .3m
.	ds #[ \f1
.	ds #] \fP
.\}
.if t \{\
.	ds #H ((1u-(\\\\n(.fu%2u))*.13m)
.	ds #V .6m
.	ds #F 0
.	ds #[ \&
.	ds #] \&
.\}
.	\" simple accents for nroff and troff
.if n \{\
.	ds ' \&
.	ds ` \&
.	ds ^ \&
.	ds , \&
.	ds ~ ~
.	ds ? ?
.	ds ! !
.	ds /
.	ds q
.\}
.if t \{\
.	ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
.	ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
.	ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
.	ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
.	ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
.	ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
.	ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
.	ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
.	ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
.\}
.	\" troff and (daisy-wheel) nroff accents
.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
.ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
.ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
.ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
.ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
.ds ae a\h'-(\w'a'u*4/10)'e
.ds Ae A\h'-(\w'A'u*4/10)'E
.ds oe o\h'-(\w'o'u*4/10)'e
.ds Oe O\h'-(\w'O'u*4/10)'E
.	\" corrections for vroff
.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
.	\" for low resolution devices (crt and lpr)
.if \n(.H>23 .if \n(.V>19 \
\{\
.	ds : e
.	ds 8 ss
.	ds v \h'-1'\o'\(aa\(ga'
.	ds _ \h'-1'^
.	ds . \h'-1'.
.	ds 3 3
.	ds o a
.	ds d- d\h'-1'\(ga
.	ds D- D\h'-1'\(hy
.	ds th \o'bp'
.	ds Th \o'LP'
.	ds ae ae
.	ds Ae AE
.	ds oe oe
.	ds Oe OE
.\}
.rm #[ #] #H #V #F C
.SH "NAME"
Apache \- Perl interface to the Apache server API
.SH "SYNOPSIS"
.PP
.Vb 1
\&   use Apache ();
.Ve
.SH "DESCRIPTION"
This module provides a Perl interface the Apache API.  It is here
mainly for \fBmod_perl\fR, but may be used for other Apache modules that
wish to embed a Perl interpreter.  We suggest that you also consult
the description of the Apache C API at http://www.apache.org/docs/.
.SH "THE REQUEST OBJECT"
The request object holds all the information that the server needs to
service a request.  Apache \fBPerl*Handler\fRs 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 \fBApache\fR 
package, it is really a \f(CWrequest_rec*\fR in disguise.
.Ip "Apache->request([$r])" 4
The Apache->request method will return a reference to the request object.
.Sp
\fBPerl*Handler\fRs can obtain a reference to the request object when it
is passed to them via \f(CW@_\fR.  However, scripts that run under 
\fBApache::Registry\fR, for example, need a way to access the request object.
\fBApache::Registry\fR will make a request object available to these scripts
by passing an object reference to \f(CWApache->request($r)\fR.
If handlers use modules such as \fB\s-1CGI::\s0Apache\fR that need to access
\f(CWApache->request\fR, they too should do this (e.g. \fBApache::Status\fR).
.Ip "$r->as_string" 4
Returns a string representation of the request object.  Mainly useful
for debugging.
.Ip "$r->main" 4
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 \f(CWundef\fR.
.Ip "$r->prev" 4
This method returns a blessed reference to the previous (internal) request
structure or \f(CWundef\fR if there is no previous request.
.Ip "$r->next" 4
This method returns a blessed reference to the next (internal) request
structure or \f(CWundef\fR if there is no next request.
.Ip "$r->last" 4
This method returns a blessed reference to the last (internal) request
structure.  Handy for logging modules.
.Ip "$r->is_main" 4
Returns true if the current request object is for the main request.
(Should give the same result as \f(CW!$r->main\fR, but will be more efficient.)
.Ip "$r->is_initial_req" 4
Returns true if the current request is the first internal request,
returns false if the request is a sub-request or internal redirect.
.SH "SUB REQUESTS"
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
\f(CWsub_req_\fR prefix here.  The \f(CWrequest_rec*\fR returned by the lookup
methods is blessed into the \fBApache::SubRequest\fR class.  This way,
\f(CWdestroy_sub_request()\fR is called automatically during
\f(CWApache::SubRequest->DESTROY\fR when the object goes out of scope.  The
\fBApache::SubRequest\fR class inherits all the methods from the
\fBApache\fR class.
.Ip "$r->lookup_uri($uri)" 4
.Sp
.Vb 2
\&   my $subr = $r->lookup_uri($uri);
\&   my $filename = $subr->filename;
.Ve
.Vb 3
\&   unless(-e $filename) {
\&       warn "can't stat $filename!\en";
\&   } 
.Ve
.Ip "$r->lookup_file($filename)" 4
.Sp
.Vb 1
\&   my $subr = $r->lookup_file($filename);
.Ve
.Ip "$subr->run" 4
.Sp
.Vb 3
\&   if($subr->run != OK) {
\&       $subr->log_error("something went wrong!");
\&   }
.Ve
.SH "CLIENT REQUEST PARAMETERS"
In this section we will take a look at various methods that can be used to
retrieve the request parameters sent from the client.
In the following examples, \fB$r\fR is a request object blessed into the 
\fBApache\fR class, obtained by the first parameter passed to a handler subroutine
or \fIApache->request\fR
.Ip "$r->method( [$meth] )" 4
The \f(CW$r\fR\->method method will return the request method.  It will be a
string such as \*(L"\s-1GET\s0\*(R", \*(L"\s-1HEAD\s0\*(R" or \*(L"\s-1POST\s0\*(R".
Passing an argument will set the method, mainly used for internal redirects.
.Ip "$r->method_number( [$num] )" 4
The \f(CW$r\fR\->method_number method will return the request method number.
The method numbers are defined by the M_GET, M_POST,... constants
available from the \fBApache::Constants\fR module.  Passing an argument
will set the method_number, mainly used for internal redirects and
testing authorization restriction masks.
.Ip "$r->bytes_sent" 4
The number of bytes sent to the client, handy for logging, etc.
.Ip "$r->the_request" 4
The request line sent by the client, handy for logging, etc.
.Ip "$r->proxyreq" 4
Returns true if the request is proxy http.
Mainly used during the filename translation stage of the request, 
which may be handled by a \f(CWPerlTransHandler\fR.
.Ip "$r->header_only" 4
Returns true if the client is asking for headers only, 
e.g. if the request method was \fB\s-1HEAD\s0\fR.
.Ip "$r->protocol" 4
The \f(CW$r\fR\->protocol method will return a string identifying the protocol
that the client speaks.  Typical values will be \*(L"\s-1HTTP/1\s0.0\*(R" or
\*(L"\s-1HTTP/1\s0.1\*(R".
.Ip "$r->hostname" 4
Returns the server host name, as set by full \s-1URI\s0 or Host: header.
.Ip "$r->request_time" 4
Returns the time that the request was made.  The time is the local unix
time in seconds since the epoch.
.Ip "$r->uri( [$uri] )" 4
The \f(CW$r\fR\->uri method will return the requested \s-1URI\s0 minus optional query
string, optionally changing it with the first argument.
.Ip "$r->filename( [$filename] )" 4
The \f(CW$r\fR\->filename method will return the result of the \fI\s-1URI\s0 -->
filename\fR translation, optionally changing it with the first argument
if you happen to be doing the translation.
.Ip "$r->path_info( [$path_info] )" 4
The \f(CW$r\fR\->path_info method will return what is left in the path after the
\fI\s-1URI\s0 --> filename\fR translation, optionally changing it with the first 
argument if you happen to be doing the translation.
.Ip "$r->args( [$query_string] )" 4
The \f(CW$r\fR\->args method will return the contents of the \s-1URI\s0 \fIquery
string\fR.  When called in a scalar context, the entire string is
returned.  When called in a list context, a list of parsed \fIkey\fR =>
\fIvalue\fR pairs are returned, i.e. it can be used like this:
.Sp
.Vb 2
\&   $query = $r->args;
\&   %in    = $r->args;
.Ve
$r->args can also be used to set the \fIquery string\fR. This can be useful
when redirecting a \s-1POST\s0 request.
.Ip "$r->headers_in" 4
The \f(CW$r\fR\->headers_in method will return a \f(CW%hash\fR of client request
headers.  This can be used to initialize a perl hash, or one could use
the \f(CW$r\fR\->\fIheader_in()\fR method (described below) to retrieve a specific
header value directly.
.Sp
Will return a \fI\s-1HASH\s0\fR reference blessed into the \fIApache::Table\fR
class when called in a scalar context with no \*(L"key\*(R" argument. This
requires \fIApache::Table\fR.
.Ip "$r->header_in( $header_name, [$value] )" 4
Return the value of a client header.  Can be used like this:
.Sp
.Vb 2
\&   $ct = $r->header_in("Content-type");
\&   $r->header_in($key, $val); #set the value of header '$key'
.Ve
.Ip "$r->content" 4
The \f(CW$r\fR\->content method will return the entity body read from the
client, but only if the request content type is
\f(CWapplication/x-www-form-urlencoded\fR.
When called in a scalar context, the entire string is
returned.  When called in a list context, a list of parsed \fIkey\fR =>
\fIvalue\fR pairs are returned.  *\s-1NOTE\s0*: you can only ask for this once,
as the entire body is read from the client.
.Ip "$r->read($buf, $bytes_to_read)" 4
This method is used to read data from the client, 
looping until it gets all of \f(CW$bytes_to_read\fR or a timeout happens.
.Sp
In addition, this method sets a timeout before reading with
\f(CW$r->hard_timeout\fR.
.Ip "$r->get_remote_host" 4
Lookup the client's \s-1DNS\s0 hostname. If the configuration directive
\fBHostNameLookups\fR is set to off, this returns the dotted decimal
representation of the client's \s-1IP\s0 address instead. Might return
\fIundef\fR if the hostname is not known.
.Ip "$r->get_remote_logname" 4
Lookup the remote user's system name.  Might return \fIundef\fR if the
remote system is not running an \s-1RFC\s0 1413 server or if the configuration
directive \fBIdentityCheck\fR is not turned on.
.PP
More information about the client can be obtained from the
\fBApache::Connection\fR object, as described below.
.Ip "$c = $r->connection" 4
The \f(CW$r\fR\->connection method will return a reference to the request
connection object (blessed into the \fBApache::Connection\fR package).
This is really a \f(CWconn_rec*\fR in disguise.  The following methods can
be used on the connection object:
.Ip "$c->remote_host" 8
If the configuration directive \fBHostNameLookups\fR is set to on:  then
the first time \f(CW$r->get_remote_host\fR is called the server does a \s-1DNS\s0
lookup to get the remote client's host name.  The result is cached in
\f(CW$c->remote_host\fR then returned. If the server was unable to resolve
the remote client's host name this will be set to "". Subsequent calls
to \f(CW$r->get_remote_host\fR return this cached value.
.Sp
If the configuration directive \fBHostNameLookups\fR is set to off: calls
to \f(CW$r->get_remote_host\fR return a string that contains the dotted
decimal representation of the remote client's \s-1IP\s0 address. However this
string is not cached, and \f(CW$c->remote_host\fR is undefined. So, it's
best to to call \f(CW$r->get_remote_host\fR instead of directly accessing
this variable.
.Ip "$c->remote_ip" 8
The dotted decimal representation of the remote client's \s-1IP\s0 address.
This is set by the server when the connection record is created so
is always defined.
.Sp
You can also set this value by providing an argument to it. This is
helpful if your server is behind a squid accelerator proxy which adds
a X\-Forwarded-For header.
.Ip "$c->local_addr" 8
A packed \s-1SOCKADDR_IN\s0 in the same format as returned by
the \f(CWpack_sockaddr_in\fR entry in the \fISocket\fR manpage, 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.
.Ip "$c->remote_addr" 8
A packed \s-1SOCKADDR_IN\s0 in the same format as returned by
the \f(CWpack_sockaddr_in\fR entry in the \fISocket\fR manpage, 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.
.Sp
Among other things, this can be used, together with \f(CW$c->local_addr\fR, to
perform \s-1RFC1413\s0 ident lookups on the remote client even when the
configuration directive \fBIdentityCheck\fR is turned off.
.Sp
Can be used like:
.Sp
.Vb 4
\&   use Net::Ident qw (lookupFromInAddr);
\&   ...
\&   my $remoteuser = lookupFromInAddr ($c->local_addr,
\&                                      $c->remote_addr, 2);
.Ve
Note that the lookupFromInAddr interface does not currently exist in
the \fBNet::Ident\fR module, but the author is planning on adding it
soon.
.Ip "$c->remote_logname" 8
If the configuration directive \fBIdentityCheck\fR is set to on:  then the
first time \f(CW$r->get_remote_logname\fR is called the server does an \s-1RFC\s0
1413 (ident) lookup to get the remote users system name. Generally for
\s-1UNI\s0* systems this is their login. The result is cached in \f(CW$c->remote_logname\fR
then returned.  Subsequent calls to \f(CW$r->get_remote_host\fR return the
cached value.
.Sp
If the configuration directive \fBIdentityCheck\fR is set to off: then 
\f(CW$r->get_remote_logname\fR does nothing and \f(CW$c->remote_logname\fR is
always undefined.
.Ip "$c->user( [$user] )" 8
If an authentication check was successful, the authentication handler
caches the user name here. Sets the user name to the optional first
argument.
.Ip "$c->auth_type" 8
Returns the authentication scheme that successfully authenticate
\f(CW$c->user\fR, if any.
.Ip "$c->aborted" 8
Returns true if the client stopped talking to us.
.Ip "$c->fileno( [$direction] )" 8
Returns the client file descriptor. If \f(CW$direction\fR is 0, the input fd
is returned. If \f(CW$direction\fR is not null or ommitted, the output fd is
returned.
.Sp
This can be used to detect client disconnect without doing any I/O,
e.g. using \s-1IO::\s0Select.
.SH "SERVER CONFIGURATION INFORMATION"
The following methods are used to obtain information from server
configuration and access control files.
.Ip "$r->dir_config( $key )" 4
Returns the value of a per-directory variable specified by the 
\f(CWPerlSetVar\fR directive.
.Sp
.Vb 3
\&   # <Location /foo/bar>
\&   # PerlSetVar  Key  Value
\&   # </Location>
.Ve
.Vb 1
\&   my $val = $r->dir_config('Key');
.Ve
Keys are case-insensitive.
.Sp
Will return a \fI\s-1HASH\s0\fR reference blessed into the
\fIApache::Table\fR class when called in a scalar context with no
\*(L"key\*(R" argument. See \fIApache::Table\fR.
.Ip "$r->requires" 4
Returns an array reference of hash references, containing information
related to the \fBrequire\fR directive.  This is normally used for access
control, see the \fIApache::AuthzAge\fR manpage for an example.
.Ip "$r->auth_type" 4
Returns a reference to the current value of the per directory
configuration directive \fBAuthType\fR. Normally this would be set to
\f(CWBasic\fR to use the basic authentication scheme defined in \s-1RFC\s0 1945,
\fIHypertext Transfer Protocol -- \s-1HTTP/1\s0.0\fR. However, you could set to
something else and implement your own authentication scheme.
.Ip "$r->auth_name" 4
Returns a reference to the current value of the per directory
configuration directive \fBAuthName\fR.  The AuthName directive creates
protection realm within the server document space. To quote \s-1RFC\s0 1945
\*(L"These realms allow the protected resources on a server to be
partitioned into a set of protection spaces, each with its own
authentication scheme and/or authorization database.\*(R" The client uses
the root \s-1URL\s0 of the server to determine which authentication
credentials to send with each \s-1HTTP\s0 request. These credentials are
tagged with the name of the authentication realm that created them.
Then during the authentication stage the server uses the current
authentication realm, from \f(CW$r->auth_name\fR, to determine which set of
credentials to authenticate.
.Ip "$r->document_root" 4
Returns a reference to the current value of the per server
configuration directive \fBDocumentRoot\fR. To quote the Apache server
documentation, \*(L"Unless matched by a directive like Alias, the server
appends the path from the requested \s-1URL\s0 to the document root to make
the path to the document.\*(R"  This same value is passed to \s-1CGI\s0
scripts in the \f(CWDOCUMENT_ROOT\fR environment variable.
.Ip "$r->allow_options" 4
The \f(CW$r->allow_options\fR method can be used for
checking if it is \s-1OK\s0 to run a perl script.  The \fBApache::Options\fR
module provides the constants to check against.
.Sp
.Vb 4
\&   if(!($r->allow_options & OPT_EXECCGI)) {
\&       $r->log_reason("Options ExecCGI is off in this directory", 
\&                      $filename);
\&   }
.Ve
.Ip "$r->get_server_port" 4
Returns the port number on which the server is listening.
.Ip "$s = $r->server" 4
Return a reference to the server info object (blessed into the
\fBApache::Server\fR package).  This is really a \f(CWserver_rec*\fR in
disguise.  The following methods can be used on the server object:
.Ip "$s = Apache->server" 4
Same as above, but only available during server startup for use in
<Perl> sections, \fBPerlScript\fR or \fBPerlModule\fR.
.Ip "$s->server_admin" 4
Returns the mail address of the person responsible for this server.
.Ip "$s->server_hostname" 4
Returns the hostname used by this server.
.Ip "$s->port" 4
Returns the port that this servers listens too.
.Ip "$s->is_virtual" 4
Returns true if this is a virtual server.
.Ip "$s->names" 4
Returns the wild-carded names for ServerAlias servers. 
.Ip "$s->dir_config( $key )" 4
Alias for Apache::dir_config.
.Ip "$s->warn" 4
Alias for Apache::warn.
.Ip "$s->log_error" 4
Alias for Apache::log_error.
.Ip "$s->uid" 4
Returns the numeric user id under which the server answers requests.
This is the value of the User directive.
.Ip "$s->gid" 4
Returns the numeric group id under which the server answers requests.
This is the value of the Group directive.
.Ip "$s->loglevel" 4
Returns the value of the current LogLevel. This method is added by
the Apache::Log module, which needs to be pulled in.
.Sp
.Vb 2
\&    use Apache::Log;
\&    print "LogLevel = ", $s->loglevel;
.Ve
If using Perl 5.005+, the following constants are defined (but not
exported):
.Sp
.Vb 8
\&    Apache::Log::EMERG
\&    Apache::Log::ALERT
\&    Apache::Log::CRIT
\&    Apache::Log::ERR
\&    Apache::Log::WARNING
\&    Apache::Log::NOTICE
\&    Apache::Log::INFO
\&    Apache::Log::DEBUG
.Ve
.Ip "$r->get_handlers( $hook )" 4
Returns a reference to a list of handlers enabled for \f(CW$hook\fR. \f(CW$hook\fR is
a string representing the phase to handle. The returned list is a list
of references to the handler subroutines.
.Sp
.Vb 1
\&        $list = $r->get_handlers( 'PerlHandler' );
.Ve
.Ip "$r->set_handlers( $hook, [\e&handler, ... ] )" 4
Sets the list if handlers to be called for \f(CW$hook\fR. \f(CW$hook\fR is a string
representing the phase to handle. The list of handlers is an anonymous
array of code references to the handlers to install for this request
phase. The special list [ \e&\s-1OK\s0 ] can be used to disable a particular
phase.
.Sp
.Vb 2
\&        $r->set_handlers( PerlLogHandler => [ \e&myhandler1, \e&myhandler2 ] );
\&        $r->set_handlers( PerlAuthenHandler => [ \e&OK ] );
.Ve
.Ip "$r->push_handlers( $hook, \e&handler )" 4
Pushes a new handler to be called for \f(CW$hook\fR. \f(CW$hook\fR is a string
representing the phase to handle. The handler is a reference to a
subroutine to install for this request phase. This handler will be
called before any configured handlers.
.Sp
.Vb 1
\&        $r->push_handlers( PerlHandler => \e&footer);
.Ve
.SH "SETTING UP THE RESPONSE"
The following methods are used to set up and return the response back
to the client.  This typically involves setting up \f(CW$r\fR\->\fIstatus()\fR, the
various content attributes and optionally some additional
\f(CW$r\fR\->\fIheader_out()\fR calls before calling \f(CW$r\fR\->\fIsend_http_header()\fR which will
actually send the headers to the client.  After this a typical
application will call the \f(CW$r\fR\->\fIprint()\fR method to send the response
content to the client.
.Ip "$r->send_http_header" 4
Send the response line and all headers to the client.
.Sp
This method will create headers from the \f(CW$r\fR\->\fIcontent_xxx()\fR and
\f(CW$r\fR\->\fIno_cache()\fR attributes (described below) and then append the
headers defined by \f(CW$r\fR\->header_out (or \f(CW$r\fR\->err_header_out if status
indicates an error).
.Ip "$r->get_basic_auth_pw" 4
If the current request is protected by Basic authentication, 
this method will return 0, otherwise \-1.  
The second return value will be the decoded password sent by the client.
.Sp
.Vb 1
\&   ($ret, $sent_pw) = $r->get_basic_auth_pw;
.Ve
.Ip "$r->note_basic_auth_failure" 4
Prior to requiring Basic authentication from the client, this method 
will set the outgoing \s-1HTTP\s0 headers asking the client to authenticate 
for the realm defined by the configuration directive \f(CWAuthName\fR.
.Ip "$r->handler( [$meth] )" 4
Set the handler for a request.
Normally set by the configuration directive \f(CWAddHandler\fR.
.Sp
.Vb 1
\&   $r->handler( "perl-script" );
.Ve
.Ip "$r->notes( $key, [$value] )" 4
Return the value of a named entry in the Apache \f(CWnotes\fR table, or
optionally set the value of a named entry.  This table is used by Apache
modules to pass messages amongst themselves. Generally if you are
writing handlers in mod_perl you can use Perl variables for this.
.Sp
.Vb 2
\&   $r->notes("MY_HANDLER" => OK);
\&   $val = $r->notes("MY_HANDLER");
.Ve
Will return a \fI\s-1HASH\s0\fR reference blessed into the \fIApache::Table\fR
class when called in a scalar context with no \*(L"key\*(R" argument. This
requires \fIApache::Table\fR.
.Ip "$r->pnotes( $key, [$value] )" 4
Like \f(CW$r\fR\->notes, but takes any scalar as an value.
.Sp
.Vb 3
\&   $r->pnotes("MY_HANDLER" => [qw(one two)]);
\&   my $val = $r->pnotes("MY_HANDLER");
\&   print $val->[0];     # prints "one"
.Ve
Advantage over just using a Perl variable is that \f(CW$r\fR\->pnotes gets
cleaned up after every request.
.Ip "$r->subprocess_env( $key, [$value] )" 4
Return the value of a named entry in the Apache \f(CWsubprocess_env\fR
table, or optionally set the value of a named entry. This table is
used by mod_include.  By setting some custom variables inside
a perl handler it is possible to combine perl with mod_include nicely.
If you say, e.g. in a PerlHeaderParserHandler
.Sp
.Vb 1
\&   $r->subprocess_env(MyLanguage => "de");
.Ve
you can then write in your .shtml document:
.Sp
.Vb 7
\&   <!--#if expr="$MyLanguage = en" -->
\&   English
\&   <!--#elif expr="$MyLanguage = de" -->
\&   Deutsch
\&   <!--#else -->
\&   Sorry
\&   <!--#endif -->
.Ve
Will return a \fI\s-1HASH\s0\fR reference blessed into the \fIApache::Table\fR
class when called in a scalar context with no \*(L"key\*(R" argument. This
requires \fIApache::Table\fR.
.Ip "$r->content_type( [$newval] )" 4
Get or set the content type being sent to the client.  Content types
are strings like \*(L"text/plain\*(R", \*(L"text/html\*(R" or \*(L"image/gif\*(R".  This
corresponds to the \*(L"Content-Type\*(R" header in the \s-1HTTP\s0 protocol.  Example
of usage is:
.Sp
.Vb 2
\&   $previous_type = $r->content_type;
\&   $r->content_type("text/plain");
.Ve
.Ip "$r->content_encoding( [$newval] )" 4
Get or set the content encoding.  Content encodings are string like
\*(L"gzip\*(R" or \*(L"compress\*(R".  This correspond to the \*(L"Content-Encoding\*(R"
header in the \s-1HTTP\s0 protocol.
.Ip "$r->content_languages( [$array_ref] )" 4
Get or set the content languages.  The content language corresponds to the
\*(L"Content-Language\*(R" \s-1HTTP\s0 header and is an array reference containing strings
such as \*(L"en\*(R" or \*(L"no\*(R".
.Ip "$r->status( $integer )" 4
Get or set the reply status for the client request.  The
\fBApache::Constants\fR module provide mnemonic names for the status codes.
.Ip "$r->status_line( $string )" 4
Get or set the response status line.  The status line is a string like
\*(L"200 Document follows\*(R" and it will take precedence over the value specified
using the \f(CW$r\fR\->\fIstatus()\fR described above.
.Ip "$r->headers_out" 4
The \f(CW$r\fR\->headers_out method will return a \f(CW%hash\fR of server response
headers.  This can be used to initialize a perl hash, or one could use
the \f(CW$r\fR\->\fIheader_out()\fR method (described below) to retrieve or set a specific
header value directly.
.Sp
Will return a \fI\s-1HASH\s0\fR reference blessed into the \fIApache::Table\fR
class when called in a scalar context with no \*(L"key\*(R" argument. This
requires \fIApache::Table\fR.
.Ip "$r->header_out( $header, $value )" 4
Change the value of a response header, or create a new one.  You
should not define any \*(L"Content-\s-1XXX\s0\*(R" headers by calling this method,
because these headers use their own specific methods.  Example of use:
.Sp
.Vb 2
\&   $r->header_out("WWW-Authenticate" => "Basic");
\&   $val = $r->header_out($key);
.Ve
.Ip "$r->err_headers_out" 4
The \f(CW$r\fR\->err_headers_out method will return a \f(CW%hash\fR of server response
headers.  This can be used to initialize a perl hash, or one could use
the \f(CW$r\fR\->\fIerr_header_out()\fR method (described below) to retrieve or set a specific
header value directly.
.Sp
The difference between headers_out and err_headers_out is that the
latter are printed even on error, and persist across internal redirects
(so the headers printed for ErrorDocument handlers will have them).
.Sp
Will return a \fI\s-1HASH\s0\fR reference blessed into the \fIApache::Table\fR
class when called in a scalar context with no \*(L"key\*(R" argument. This
requires \fIApache::Table\fR.
.Ip "$r->err_header_out( $header, [$value] )" 4
Change the value of an error response header, or create a new one.
These headers are used if the status indicates an error.
.Sp
.Vb 2
\&   $r->err_header_out("Warning" => "Bad luck");
\&   $val = $r->err_header_out($key);
.Ve
.Ip "$r->no_cache( $boolean )" 4
This is a flag that indicates that the data being returned is volatile
and the client should be told not to cache it.
.Ip "$r->print( @list )" 4
This method sends data to the client with \f(CW$r->write_client\fR, but first
sets a timeout before sending with \f(CW$r->hard_timeout\fR. This method is
called instead of \s-1CORE::\s0print when you use \fIprint()\fR in your mod_perl programs.
.Sp
This method treats scalar references specially. If an item in \f(CW@list\fR 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 \fIprint()\fR behavior.
.Sp
Example:
.Sp
.Vb 1
\&   $foo = \e"bar"; print($foo);
.Ve
The result is \*(L"bar\*(R", not the \*(L"\fI\s-1SCALAR\s0\fR\|(0xDEADBEEF)\*(R" you might have expected. If
you really want the reference to be printed out, force it into a scalar
context by using \f(CWprint(scalar($foo))\fR.
.Ip "$r->send_fd( $filehandle )" 4
Send the contents of a file to the client.  Can for instance be used
like this:
.Sp
.Vb 3
\&  open(FILE, $r->filename) || return 404;
\&  $r->send_fd(FILE);
\&  close(FILE);
.Ve
.Ip "$r->internal_redirect( $newplace )" 4
Redirect to a location in the server namespace without 
telling the client. For instance:
.Sp
.Vb 1
\&   $r->internal_redirect("/home/sweet/home.html");
.Ve
.Ip "$r->internal_redirect_handler( $newplace )" 4
Same as \fIinternal_redirect\fR, but the \fIhandler\fR from \f(CW$r\fR is preserved.
.Ip "$r->custom_response($code, $uri)" 4
This method provides a hook into the \fBErrorDocument\fR mechanism,
allowing you to configure a custom response for a given response
code at request-time.
.Sp
Example:
.Sp
.Vb 1
\&    use Apache::Constants ':common';
.Ve
.Vb 2
\&    sub handler {
\&        my($r) = @_;
.Ve
.Vb 3
\&        if($things_are_ok) {
\&            return OK;
\&        }
.Ve
.Vb 3
\&        #<Location $r->uri>
\&        #ErrorDocument 401 /error.html
\&        #</Location>
.Ve
.Vb 1
\&        $r->custom_response(AUTH_REQUIRED, "/error.html");
.Ve
.Vb 4
\&        #can send a string too
\&        #<Location $r->uri>
\&        #ErrorDocument 401 "sorry, go away"
\&        #</Location>
.Ve
.Vb 1
\&        #$r->custom_response(AUTH_REQUIRED, "sorry, go away");
.Ve
.Vb 2
\&        return AUTH_REQUIRED;
\&    }
.Ve
.SH "SERVER CORE FUNCTIONS"
.Ip "$r->soft_timeout($message)" 4
.Ip "$r->hard_timeout($message)" 4
.Ip "$r->kill_timeout" 4
.Ip "$r->reset_timeout" 4
(Documentation borrowed from http_main.h)
.Sp
There are two functions which modules can call to trigger a timeout
(with the per-virtual-server timeout duration); these are hard_timeout
and soft_timeout.
.Sp
The difference between the two is what happens when the timeout
expires (or earlier than that, if the client connection aborts) ---
a soft_timeout just puts the connection to the client in an
\*(L"aborted\*(R" state, which will cause http_protocol.c to stop trying to
talk to the client, but otherwise allows the code to continue normally.
\fIhard_timeout()\fR, by contrast, logs the request, and then aborts it
completely --- \fIlongjmp()\fRing out to the \fIaccept()\fR loop in http_main.
Any resources tied into the request resource pool will be cleaned up;
everything that is not will leak.
.Sp
\fIsoft_timeout()\fR is recommended as a general rule, because it gives your
code a chance to clean up.  However, \fIhard_timeout()\fR 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.
.Sp
When a hard timeout is in scope, critical sections can be guarded
with \fIblock_alarms()\fR and \fIunblock_alarms()\fR --- these are declared in
alloc.c because they are most often used in conjunction with
routines 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 http_main.c.
.Sp
\fIkill_timeout()\fR will disarm either variety of timeout.
.Sp
\fIreset_timeout()\fR resets the timeout in progress.
.Ip "$r->post_connection($code_ref)" 4
.Ip "$r->register_cleanup($code_ref)" 4
Register a cleanup function which is called just before \f(CW$r\fR\->pool is
destroyed.
.Sp
.Vb 4
\&   $r->register_cleanup(sub {
\&       my $r = shift;
\&       warn "registered cleanup called for ", $r->uri, "\en";
\&   });
.Ve
The \fIpost_connection\fR method is simply an alias for \fIregister_cleanup\fR, 
as this method may be used to run code after the client connection is closed,
which may not be a \fIcleanup\fR.
.SH "CGI SUPPORT"
We also provide some methods that make it easier to support the CGI
type of interface.
.Ip "$r->send_cgi_header()" 4
Take action on certain headers including \fIStatus:\fR, \fILocation:\fR and
\fIContent-type:\fR just as mod_cgi does, then calls
\f(CW$r\fR\->\fIsend_http_header()\fR.  Example of use:
.Sp
.Vb 3
\&   $r->send_cgi_header(<<EOT);
\&   Location: /foo/bar
\&   Content-type: text/html
.Ve
.Vb 1
\&   EOT
.Ve
.SH "ERROR LOGGING"
The following methods can be used to log errors. 
.Ip "$r->log_reason($message, $file)" 4
The request failed, why??  Write a message to the server errorlog.
.Sp
.Vb 1
\&   $r->log_reason("Because I felt like it", $r->filename);
.Ve
.Ip "$r->log_error($message)" 4
Uh, oh.  Write a message to the server errorlog.
.Sp
.Vb 1
\&   $r->log_error("Some text that goes in the error_log");
.Ve
.Ip "$r->warn($message)" 4
For pre-1.3 versions of apache, this is just an alias for
\f(CWlog_error\fR.  With 1.3+ versions of apache, this message will only be
send to the error_log if \fBLogLevel\fR is set to \fBwarn\fR or higher. 
.SH "UTILITY FUNCTIONS"
.Ip "Apache::unescape_url($string)" 4
Handy function for unescapes.  Use this one for filenames/paths.
Use unescape_url_info for the result of submitted form data.
.Ip "Apache::unescape_url_info($string)" 4
Handy function for unescapes submitted form data.
In opposite to unescape_url it translates the plus sign to space.
.Ip "Apache::perl_hook($hook)" 4
Returns true if the specified callback hook is enabled:
.Sp
.Vb 5
\&   for (qw(Access Authen Authz ChildInit Cleanup Fixup
\&           HeaderParser Init Log Trans Type))
\&   {
\&       print "$_ hook enabled\en" if Apache::perl_hook($_);
\&   }  
.Ve
.SH "GLOBAL VARIABLES"
.Ip "$Apache::Server::Starting" 4
Set to true when the server is starting.
.Ip "$Apache::Server::ReStarting" 4
Set to true when the server is starting.
.Ip "$Apache::Server::ConfigTestOnly" 4
Set to true when the server is running in configuration test mode
(\f(CWhttpd -t\fR).
.Sp
.Vb 9
\&   <Perl>
\&    # don't continue if it's a config test!
\&    print("Skipping the <Perl> code!\en"),
\&    return if $Apache::Server::ConfigTestOnly;
\&   
\&    print "Running the <Perl> code!\en"
\&    # some code here
\&   
\&   </Perl>
.Ve
.SH "SEE ALSO"
\fIperl\fR\|(1),
\fIApache::Constants\fR\|(3),
\fIApache::Registry\fR\|(3),
\fIApache::Debug\fR\|(3),
\fIApache::Options\fR\|(3),
\fICGI::Apache\fR\|(3)
.PP
Apache C API notes at \f(CWhttp://www.apache.org/docs/\fR
.SH "AUTHORS"
Perl interface to the Apache C API written by Doug MacEachern
with contributions from Gisle Aas, Andreas Koenig, Eric Bartley, 
Rob Hartill, Gerald Richter, Salvador Ortiz and others. 

.rn }` ''
.IX Title "Apache 3"
.IX Name "Apache - Perl interface to the Apache server API"

.IX Header "NAME"

.IX Header "SYNOPSIS"

.IX Header "DESCRIPTION"

.IX Header "THE REQUEST OBJECT"

.IX Item "Apache->request([$r])"

.IX Item "$r->as_string"

.IX Item "$r->main"

.IX Item "$r->prev"

.IX Item "$r->next"

.IX Item "$r->last"

.IX Item "$r->is_main"

.IX Item "$r->is_initial_req"

.IX Header "SUB REQUESTS"

.IX Item "$r->lookup_uri($uri)"

.IX Item "$r->lookup_file($filename)"

.IX Item "$subr->run"

.IX Header "CLIENT REQUEST PARAMETERS"

.IX Item "$r->method( [$meth] )"

.IX Item "$r->method_number( [$num] )"

.IX Item "$r->bytes_sent"

.IX Item "$r->the_request"

.IX Item "$r->proxyreq"

.IX Item "$r->header_only"

.IX Item "$r->protocol"

.IX Item "$r->hostname"

.IX Item "$r->request_time"

.IX Item "$r->uri( [$uri] )"

.IX Item "$r->filename( [$filename] )"

.IX Item "$r->path_info( [$path_info] )"

.IX Item "$r->args( [$query_string] )"

.IX Item "$r->headers_in"

.IX Item "$r->header_in( $header_name, [$value] )"

.IX Item "$r->content"

.IX Item "$r->read($buf, $bytes_to_read)"

.IX Item "$r->get_remote_host"

.IX Item "$r->get_remote_logname"

.IX Item "$c = $r->connection"

.IX Item "$c->remote_host"

.IX Item "$c->remote_ip"

.IX Item "$c->local_addr"

.IX Item "$c->remote_addr"

.IX Item "$c->remote_logname"

.IX Item "$c->user( [$user] )"

.IX Item "$c->auth_type"

.IX Item "$c->aborted"

.IX Item "$c->fileno( [$direction] )"

.IX Header "SERVER CONFIGURATION INFORMATION"

.IX Item "$r->dir_config( $key )"

.IX Item "$r->requires"

.IX Item "$r->auth_type"

.IX Item "$r->auth_name"

.IX Item "$r->document_root"

.IX Item "$r->allow_options"

.IX Item "$r->get_server_port"

.IX Item "$s = $r->server"

.IX Item "$s = Apache->server"

.IX Item "$s->server_admin"

.IX Item "$s->server_hostname"

.IX Item "$s->port"

.IX Item "$s->is_virtual"

.IX Item "$s->names"

.IX Item "$s->dir_config( $key )"

.IX Item "$s->warn"

.IX Item "$s->log_error"

.IX Item "$s->uid"

.IX Item "$s->gid"

.IX Item "$s->loglevel"

.IX Item "$r->get_handlers( $hook )"

.IX Item "$r->set_handlers( $hook, [\e&handler, ... ] )"

.IX Item "$r->push_handlers( $hook, \e&handler )"

.IX Header "SETTING UP THE RESPONSE"

.IX Item "$r->send_http_header"

.IX Item "$r->get_basic_auth_pw"

.IX Item "$r->note_basic_auth_failure"

.IX Item "$r->handler( [$meth] )"

.IX Item "$r->notes( $key, [$value] )"

.IX Item "$r->pnotes( $key, [$value] )"

.IX Item "$r->subprocess_env( $key, [$value] )"

.IX Item "$r->content_type( [$newval] )"

.IX Item "$r->content_encoding( [$newval] )"

.IX Item "$r->content_languages( [$array_ref] )"

.IX Item "$r->status( $integer )"

.IX Item "$r->status_line( $string )"

.IX Item "$r->headers_out"

.IX Item "$r->header_out( $header, $value )"

.IX Item "$r->err_headers_out"

.IX Item "$r->err_header_out( $header, [$value] )"

.IX Item "$r->no_cache( $boolean )"

.IX Item "$r->print( @list )"

.IX Item "$r->send_fd( $filehandle )"

.IX Item "$r->internal_redirect( $newplace )"

.IX Item "$r->internal_redirect_handler( $newplace )"

.IX Item "$r->custom_response($code, $uri)"

.IX Header "SERVER CORE FUNCTIONS"

.IX Item "$r->soft_timeout($message)"

.IX Item "$r->hard_timeout($message)"

.IX Item "$r->kill_timeout"

.IX Item "$r->reset_timeout"

.IX Item "$r->post_connection($code_ref)"

.IX Item "$r->register_cleanup($code_ref)"

.IX Header "CGI SUPPORT"

.IX Item "$r->send_cgi_header()"

.IX Header "ERROR LOGGING"

.IX Item "$r->log_reason($message, $file)"

.IX Item "$r->log_error($message)"

.IX Item "$r->warn($message)"

.IX Header "UTILITY FUNCTIONS"

.IX Item "Apache::unescape_url($string)"

.IX Item "Apache::unescape_url_info($string)"

.IX Item "Apache::perl_hook($hook)"

.IX Header "GLOBAL VARIABLES"

.IX Item "$Apache::Server::Starting"

.IX Item "$Apache::Server::ReStarting"

.IX Item "$Apache::Server::ConfigTestOnly"

.IX Header "SEE ALSO"

.IX Header "AUTHORS"

