The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Apache::RequestUtil - Perl API for Apache request record utils

Synopsis

  use Apache::RequestUtil ();
  
  # directory level PerlOptions flags lookup
  $r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');

META: to be completed

Description

META: to be completed

Class methods API

request

Retrieve the (Apache::RequestRec) object for the current request.

  $r = Apache->request;
obj: Apache (class name)

The Apache class

ret: $r (Apache::RequestRec)
since: 1.99_10

This method is only available if PerlOptions +GlobalRequest is in effect.

Methods API

default_type

META: Autogenerated - needs to be reviewed/completed

Retrieve the value of the DefaultType directive, or text/plain if not set

  $ret = $r->default_type();
obj: $r (Apache::RequestRec)

The current request

ret: $ret (string)

The default type

document_root

META: Autogenerated - needs to be reviewed/completed

Retrieve the document root for this server

  $ret = $r->document_root();
obj: $r (Apache::RequestRec)

The current request

ret: $ret (string)

The document root

get_limit_req_body

META: Autogenerated - needs to be reviewed/completed

Return the limit on bytes in request msg body

  $ret = $r->get_limit_req_body();
obj: $r (Apache::RequestRec)

The current request

ret: $ret (integer)

the maximum number of bytes in the request msg body

get_server_name

META: Autogenerated - needs to be reviewed/completed

Get the current server name from the request

  $ret = $r->get_server_name();
obj: $r (Apache::RequestRec)

The current request

ret: $ret (string)

the server name

get_server_port

META: Autogenerated - needs to be reviewed/completed

Get the current server port

  $ret = $r->get_server_port();
obj: $r (Apache::RequestRec)
ret: $ret (integer)

The server's port

get_status_line

META: Autogenerated - needs to be reviewed/completed

Return the Status-Line for a given status code (excluding the HTTP-Version field). If an invalid or unknown status code is passed, "500 Internal Server Error" will be returned.

  $ret = get_status_line($status);
obj: $status (integer)

The HTTP status code

ret: $ret (string)

The Status-Line

is_initial_req

META: Autogenerated - needs to be reviewed/completed

Determine if the current request is the main request or a sub requests

  $ret = $r->is_initial_req();
obj: $r (Apache::RequestRec)

The current request

ret: $ret (integer)

method_register

META: Autogenerated - needs to be reviewed/completed

Register a new request method, and return the offset that will be associated with that method.

  $ret = $p->method_register($methname);
obj: $p (APR::Pool)

The pool to create registered method numbers from.

arg1: $methname (string)

The name of the new method to register.

ret: $ret (integer)

Ab int value representing an offset into a bitmask.

add_config

META: Autogenerated - needs to be reviewed/completed

  $ret = $r->add_config($lines, $path, $override);
obj: $r (Apache::RequestRec)
arg1: $lines (ARRAY ref)
opt arg3: $path (scalar)
opt arg4: $override (string)
ret: $ret (string)

See also: $s->add_config

location

META: Autogenerated - needs to be reviewed/completed

  $location = $r->location($location);
obj: $r (Apache::RequestRec)
opt arg2: $location (string)
ret: $location (integer)

location_merge

META: Autogenerated - needs to be reviewed/completed

  $ret = $r->location_merge($location);
obj: $r (Apache::RequestRec)
arg1: $location (string)
ret: $ret (integer)

pnotes

META: Autogenerated - needs to be reviewed/completed

Notes from one module to another

  $pnotes = $r->pnotes();
  $pnotes = $r->pnotes($new_pnotes);
obj: $r (Apache::RequestRec)
opt arg2: $new_pnotes (APR::Table)
ret: $pnotes (APR::Table)

Similar to (Apache::RequestRec), but values can be any perl variables. That also means that it can be used only between perl modules.

no_cache

META: Autogenerated - needs to be reviewed/completed

  $ret = $r->no_cache($flag);
obj: $r (Apache::RequestRec)
arg1: $flag (number)
ret: $ret (integer)

as_string

META: Autogenerated - needs to be reviewed/completed

  $string = $r->as_string();
obj: $r (Apache::RequestRec)
ret: $string (string)

get_handlers

Returns a reference to a list of handlers enabled for a given phase.

  $handlers_list = $r->get_handlers($hook_name);
obj: $r (Apache::RequestRec)
arg1: $hook_name (string)

a string representing the phase to handle.

ret: @handlers (CODE ref or ref to ARRAY of CODE refs)

a list of handler subroutines CODE references

For example:

A list of handlers configured to run at the response phase:

  my @handlers = @{ $r->get_handlers('PerlResponseHandler') || [] };

push_handlers

Add one or more handlers to a list of handlers to be called for a given phase.

  $r->push_handlers($hook_name => \&handler);
  $r->push_handlers($hook_name => ['Foo::Bar::handler', \&handler2]);
obj: $r (Apache::RequestRec)
arg1: $hook_name (string)

a string representing the phase to handle.

arg2: $handlers (CODE ref or SUB name or ref to an ARRAY of CODE refs)

a single handler CODE reference or just a name of the subroutine (fully qualified unless defined in the current package).

if more than one passed, use a reference to an array of CODE refs and/or subroutine names.

ret: no return value

Examples:

A single handler:

  $r->push_handlers(PerlResponseHandler => \&handler);

Multiple handlers:

  $r->push_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);

Anonymous functions:

  $r->push_handlers(PerlLogHandler => sub { return Apache::OK });

set_handlers

Set a list of handlers to be called for a given phase. Any previously set handlers are forgotten.

  $r->set_handlers($hook_name => \&handler);
  $r->set_handlers($hook_name => ['Foo::Bar::handler', \&handler2]);
  $r->set_handlers($hook_name => []);
  $r->set_handlers($hook_name => undef);
obj: $r (Apache::RequestRec)
arg1: $hook_name (string)

a string representing the phase to handle.

arg2: $handlers (CODE ref or SUB name or ref to an ARRAY of CODE refs)

a reference to a single handler CODE reference or just a name of the subroutine (fully qualified unless defined in the current package).

if more than one passed, use a reference to an array of CODE refs and/or subroutine names.

if the argument is undef or [] the list of handlers is reset to zero.

ret: no return value

Examples:

A single handler:

  $r->set_handlers(PerlResponseHandler => \&handler);

Multiple handlers:

  $r->set_handlers(PerlFixupHandler => ['Foo::Bar::handler', \&handler2]);

Anonymous functions:

  $r->set_handlers(PerlLogHandler => sub { return Apache::OK });

Reset any previously set handlers:

  $r->set_handlers(PerlCleanupHandler => []);

or

  $r->set_handlers(PerlCleanupHandler => undef);

set_basic_credentials

META: Autogenerated - needs to be reviewed/completed

  $r->set_basic_credentials($username, $password);
obj: $r (Apache::RequestRec)
arg1: $username (string)
arg2: $password (string)
ret: no return value

slurp_filename

META: Autogenerated - needs to be reviewed/completed

Return a reference to contents of $r->filename.

  $content = $r->slurp_filename($tainted);
obj: $r (Apache::RequestRec)
arg1: $tainted (number)

By default the returned data is tainted (if run under -T). If an optional $tainted flag is set to zero, the data will be marked as non-tainted. Do not set this flag to zero unless you know what you are doing, you may create a security hole in your program if you do. For more information see the perlsec manpage. If you wonder why this option is available, it is used internally by the ModPerl::Registry handler and friends, because the CGI scripts that it reads are considered safe (you could just as well require() them).

ret: $content (scalar)

is_perl_option_enabled

check whether a directory level PerlOptions flag is enabled or not.

  $result = $r->is_perl_option_enabled($flag);
obj: $r (Apache::RequestRec)
arg1: $flag (string)
ret: $result (integer)

For example to check whether the SetupEnv option is enabled for the current request (which can be disabled with PerlOptions -SetupEnv) and populate the environment variables table if disabled:

  $r->subprocess_env unless $r->is_perl_option_enabled('SetupEnv');

See also: PerlOptions and the equivalent function for server level PerlOptions flags.

dir_config

dir_config() provides an interface for the per-directory variable specified by the PerlSetVar and PerlAddVar directives, and also can be manipulated via the APR::Table methods.

  $table  = $r->dir_config();
  $value  = $r->dir_config($key);
  @values = $r->dir_config($key);
  $r->dir_config($key, $val);
obj: $r (Apache::RequestRec)
opt arg2: $key (string)
opt arg3: $val (string)
ret: $ret (scalar)

Depends on the passed arguments, see further discussion

The keys are case-insensitive.

  $apr_table = $r->dir_config();

dir_config() called in a scalar context without the $key argument returns a HASH reference blessed into the APR::Table class. This object can be manipulated via the APR::Table methods. For available methods see the APR::Table manpage.

  @values = $r->dir_config($key);

If the $key argument is passed in the list context a list of all matching values will be returned. This method is ineffective for big tables, as it does a linear search of the table. Thefore avoid using this way of calling dir_config() unless you know that there could be more than one value for the wanted key and all the values are wanted.

  $value = $r->dir_config($key);

If the $key argument is passed in the scalar context only a single value will be returned. Since the table preserves the insertion order, if there is more than one value for the same key, the oldest value assosiated with the desired key is returned. Calling in the scalar context is also much faster, as it'll stop searching the table as soon as the first match happens.

  $r->dir_config($key => $val);

If the $key and the $val arguments are used, the set() operation will happen: all existing values associated with the key $key (and the key itself) will be deleted and $value will be placed instead.

  $r->dir_config($key => undef);

If $val is undef the unset() operation will happen: all existing values associated with the key $key (and the key itself) will be deleted.

See Also

mod_perl 2.0 documentation.

Copyright

mod_perl 2.0 and its core modules are copyrighted under The Apache Software License, Version 1.1.

Authors

The mod_perl development team and numerous contributors.