use Apache ();
request_rec * in disguise.
Perl*Handler's can obtain a reference to the request object when it is passed to them
via @_. However, scripts that run under
Registry, for example, need a way to access the request object.
Registry will make a request object availible to these scripts by passing it's
object reference to Apache-request>. If handlers use modules such as Apache::CGI that need to access
Apache-request>, they too should do this (e.g. Apache::Status).
PerlTransHandler.
$query = $r->args; %in = $r->args;
%hash of client
request headers. This can be used to initialize a perl hash, or one could
use the $r->header_in() method (described below) to retrieve a specific
header value directly.
$ct = $r->header_in("Content-type");
$r->header_in($key, $val); #set the value of header '$key'
application/x-www-form-urlencoded. 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.
*NOTE*: you can only ask for this once, as the entire
body is read from the client.
$r->read_client_block($buf, $r->header_in('Content-length'));
read_client_block to read data from the
client, looping until it gets all of $bytes_to_read or a timeout happens.
In addition, this method sets a timeout before reading with
$r-hard_timeout>
conn_rec* in disguise. The following methods can be used on the connection object:
$c->remote_host
$c->remote_ip
$c->remote_logname
$c->user; #Returns the remote username if authenticated.
$c->auth_type; #Returns the authentication scheme used, if any.
$c->aborted; #returns true if the client stopped talking to us
$c->close; #Calling this method will close down the connection to the client
PerlSetVar directive.
#<Location /foo/bar> #SetPerlVar Key Value #</Location>
my $val = $r->dir_config('Key');
if(!($r->allow_options & OPT_EXECCGI)) {
$r->log_reason("Options ExecCGI is off in this directory",
$filename);
}
server_rec* in disguise. The following methods can be used on the server object:
This method will create headers from the $r->content_xxx() and $r->no_cache() attributes (described below) and then append the headers defined by $r->header_out (or $r->err_header_out if status indicates an error).
($ret, $sent_pw) = $r->get_basic_auth_pw;
AuthName.
AddHandler. $r->handler( ``perl-script'' );
$previous_type = $r->content_type;
$r->content_type("text/plain");
%hash of server
response headers. This can be used to initialize a perl hash, or one could
use the $r->header_out() method (described below) to retrieve or set a
specific header value directly.
$r->header_out("WWW-Authenticate" => "Basic");
$val = $r->header_out($key);
%hash of
server response headers. This can be used to initialize a perl hash, or one
could use the $r->err_header_out() method (described below) to retrieve
or set a specific header value directly.
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).
$r->err_header_out("Warning" => "Bad luck");
$val = $r->err_header_out($key);
$r-write_client>, but first sets a timeout before sending with $r-hard_timeout>.
open(FILE, $r->filename) || return 404; $r->send_fd(FILE); close(FILE);
$r->internal_redirect_handler("/home/sweet/home.html");
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.
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 ``aborted'' state, which will cause
http_protocol.c to stop trying to talk to the client, but otherwise allows
the code to continue normally. hard_timeout, by contrast, logs
the request, and then aborts it completely --- longjmping out
to the accept loop in http_main. Any resources tied into the
request's resource pool will be cleaned up; everything that isn't will
leak.
soft_timeout is recommended as a general rule, because it
gives your code a chance to clean up. However, hard_timeout
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 guarded with
block_alarms and unblock_alarms --- 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.
kill_timeout will disarm either variety of timeout.
reset_timeout resets the timeout in progress.
%hash that can be used to set up a standard
CGI environment. Typical usage would be:
%ENV = $r->cgi_env
NOTE: The
$ENV{GATEWAY_INTERFACE} is set to 'CGI-Perl/1.1' so you can say:
if($ENV{GATEWAY_INTERFACE} =~ /^CGI-Perl/) {
#do mod_perl stuff
}
else {
#do normal CGI stuff
}
When given a key => value pair, this will set an environment variable.
$r->cgi_env(REMOTE_GROUP => "camels");
my $doc_root = $r->cgi_env('DOCUMENT_ROOT');
$r->send_cgi_header("
Location: /foo/bar
Content-type: text/html
");
$r->log_reason("Because I felt like it", $r->filename);
$r->log_error("Some text that goes in the error_log");
for (qw(Access Authen Authz Fixup HeaderParser Log Trans Type)) {
print "$_ hook enabled\n" if Apache::perl_hook($_);
}
perl, Apache::Constants(3), Apache::Registry(3),
Apache::CGI(3), Apache::Debug(3), Apache::Options(3)