Apache2-API
view release on metacpan or search on metacpan
lib/Apache2/API/Request.pm view on Meta::CPAN
sub document_root { return( shift->_try( 'request', 'document_root', @_ ) ); }
sub document_uri { return( shift->env( 'document_uri', @_ ) ); }
sub encode
{
my $self = shift( @_ );
return( APR::Request::encode( shift( @_ ) ) );
}
sub env
{
my $self = shift( @_ );
my $r = $self->request;
if( @_ )
{
if( scalar( @_ ) == 1 )
{
my $v = shift( @_ );
if( ref( $v ) eq 'HASH' )
{
foreach my $k ( sort( keys( %$v ) ) )
{
$r->subprocess_env( $k => $v->{ $k } );
}
}
else
{
return( $r->subprocess_env( $v ) );
}
}
else
{
my $hash = { @_ };
foreach my $k ( sort( keys( %$hash ) ) )
{
$r->subprocess_env( $k => $hash->{ $k } );
}
}
}
else
{
$r->subprocess_env;
}
}
sub err_headers_out { return( shift->_headers( 'err_headers_out', @_ ) ); }
sub filename { return( shift->_try( 'request', 'filename' ) ); }
# APR::Finfo
sub finfo { return( shift->_try( 'request', 'finfo' ) ) }
# example: CGI/1.1
sub gateway_interface { return( shift->env( 'GATEWAY_INTERFACE', @_ ) ); }
# $handlers_list = $r->get_handlers($hook_name);
# https://perl.apache.org/docs/2.0/api/Apache2/RequestUtil.html#C_get_handlers_
sub get_handlers { return( shift->_try( 'request', 'get_handlers', @_ ) ); }
# e.g. get_status_line( 404 ) would return 404 Not Found
sub get_status_line { return( shift->_try( 'request', 'get_status_line', @_ ) ); }
sub global_request { return( Apache2::RequestUtil->request ); }
sub has_auth { return( shift->_try( 'request', 'some_auth_required' ) ); }
sub header
{
my $self = shift( @_ );
return( $self->error( "No header field name was provided to set or retrieve its value." ) ) if( !scalar( @_ ) );
my $field = shift( @_ );
my $hdrs = $self->headers || return( $self->pass_error );
if( scalar( @_ ) > 1 )
{
return( $hdrs->set( "$field" => @_ ) );
}
else
{
return( $hdrs->get( "$field" ) );
}
}
sub header_only { return( shift->request->header_only ); }
# sub headers { return( shift->request->headers_in ); }
sub headers { return( shift->_headers( 'headers_in', @_ ) ); }
sub headers_as_hashref
{
my $self = shift( @_ );
my $ref = {};
my $h = $self->headers;
while( my( $k, $v ) = each( %$h ) )
{
if( CORE::exists( $ref->{ $k } ) )
{
# if( ref( $ref->{ $k } ) eq 'ARRAY' )
if( $self->_is_array( $ref->{ $k } ) )
{
CORE::push( @{$ref->{ $k }}, $v );
}
else
{
my $old = $ref->{ $k };
$ref->{ $k } = [];
CORE::push( @{$ref->{ $k }}, $old, $v );
}
}
else
{
$ref->{ $k } = $v;
}
}
return( $ref );
}
sub headers_as_json
{
my $self = shift( @_ );
my $ref = $self->headers_as_hashref;
lib/Apache2/API/Request.pm view on Meta::CPAN
my $limit = $req->brigade_limit;
my $charset = $req->charset;
$req->child_terminate;
my $api_version = $req->client_api_version;
# close client connection
$req->close;
my $status_code = $req->code;
# Apache2::Connection
my $conn = $req->connection;
my $id = $req->connection_id;
# content of the request filename
my $content = $req->content;
my $encoding = $req->content_encoding;
my $langs_array_ref = $req->content_languages;
my $len = $req->content_length;
# text/plain
my $ct = $req->content_type;
# Get a Cookie object
my $cookie = $req->cookie( $name );
# Cookie::Jar object
my $jar = $req->cookies;
# get data string sent by client
my $data = $req->data;
my $formatter = $req->datetime;
my $decoded = $req->decode( $string );
my $do_not_track = $req->dnt;
my $encoded = $req->encode( $string );
$req->discard_request_body(1);
my $document_root = $req->document_root;
my $url = $req->document_uri;
# APR::Table object
my $hash_ref = $req->env;
my $headers = $req->err_headers_out;
# request filename
my $filename = $req->filename;
# APR::Finfo object
my $finfo = $req->finfo;
# e.g.: CGI/1.1
my $gateway = $req->gateway_interface;
my $code_ref = $req->get_handlers( $name );
# 404 Not Found
my $str = $req->get_status_line(404);
my $r = $req->global_request;
my $is_head = $req->header_only;
# same
my $is_head = $req->is_header_only;
my $content_type = $req->headers( 'Content-Type' );
# or (since it is case insensitive)
my $content_type = $req->headers( 'content-type' );
# or
my $content_type = $req->headers->{'Content-Type'};
$req->headers( 'Content-Type' => 'text/plain' );
# or
$req->headers->{'Content-Type'} = 'text/plain';
# APR::Table object
my $headers = $req->headers;
my $hash_ref = $req->headers_as_hashref;
my $json = $req->headers_as_json;
my $headers = $req->headers_in;
my $out = $req->headers_out;
my $hostname = $req->hostname;
my $uri_host = $req->http_host;
my $conn_id = $req->id;
my $if_mod = $req->if_modified_since;
my $if_no_match = $req->if_none_match;
my $filters = $req->input_filters;
my $bool = $req->is_aborted;
my $enabled = $req->is_perl_option_enabled;
# running under https?
my $secure = $req->is_secure;
# JSON object
my $json = $req->json;
my $keepalive = $req->keepalive;
my $keepalives = $req->keepalives;
my $ok_languages = $req->languages;
my $nbytes = $req->length;
# APR::SockAddr object
my $addr = $req->local_addr;
my $host = $req->local_host;
my $str = $req->local_ip;
my $loc = $req->location;
$req->log_error( "Oh no!" );
# 200kb
$req->max_size(204800);
my $http_method = $req->method;
my $meth_num = $req->method_number;
# mod_perl/2.0.11
my $mod_perl = $req->mod_perl;
my $vers = $req->mod_perl_version;
my $seconds = $req->mtime;
lib/Apache2/API/Request.pm view on Meta::CPAN
my $rc = $req->discard_request_body;
return( $rc ) if( $rc != Apache2::Const::OK );
This method calls L<Apache2::RequestIO/discard_request_body>
=head2 dnt
Sets or gets the environment variable C<HTTP_DNT> using L<Apache2::RequestRec/subprocess_env>. See L</env> below for more on that.
This is an abbreviation for C<Do not track>
If available, typical value is a boolean such as C<0> or C<1>
=head2 document_root
Sets or retrieve the document root for this server.
If a value is provided, it sets the document root to a new value only for the duration of the current request.
See L<Apache2::RequestUtil> for more information.
=head2 document_uri
Get the value for the environment variable C<DOCUMENT_URI>.
=head2 encode
Given a string, this returns its url-encoded version
This uses L<APR::Request> XS method.
=head2 env
my $val = $req->env( $name );
$req->env( $name, $value );
Using the Apache C<subprocess_env> table, this sets or gets environment variables. This is the equivalent of this:
$req->subprocess_env;
$env_table = $req->subprocess_env;
$req->subprocess_env( $key => $val );
$val = $req->subprocess_env( $key );
where C<$req> is this module object.
If one argument is provided, it will return the corresponding environment value.
If one or more sets of key-value pair are provided, they are set accordingly.
If nothing is provided, it returns a L<APR::Table> object.
=head2 err_headers_out
Get or sets HTTP response headers, which are printed out even on errors and persist across internal redirects.
According to the L<Apache2::RequestRec> documentation:
The difference between L</headers_out> (L<Apache2::RequestRec/headers_out>) and L</err_headers_out> (L<Apache2::RequestRec/err_headers_out>), is that the latter are printed even on error, and persist across internal redirects (so the headers printed ...
For example, if a handler wants to return a C<404> response, but nevertheless to set a cookie, it has to be:
$req->err_headers_out->add( 'Set-Cookie' => $cookie );
return( Apache2::Const::NOT_FOUND );
If the handler does:
$req->headers_out->add( 'Set-Cookie' => $cookie );
return( Apache2::Const::NOT_FOUND );
the C<Set-Cookie> header will not be sent.
See L<Apache2::RequestRec> for more information.
=head2 filename
Get or sets the filename (full file path) on disk corresponding to this request or response, by calling L<Apache2::RequestRec/filename>
See L<Apache2::RequestRec/filename> for more information.
=head2 finfo
Get and set the finfo request record member, by calling L<Apache2::RequestRec/finfo>
See L<Apache2::RequestRec/finfo> for more information.
=head2 gateway_interface
Sets or gets the environment variable C<GATEWAY_INTERFACE> using L</env>
Typical value returned from the environment variable C<GATEWAY_INTERFACE> is C<CGI/1.1>
=head2 get_handlers
Returns a reference to a list of handlers enabled for a given phase.
$handlers_list = $req->get_handlers( $hook_name );
Example, a list of handlers configured to run at the response phase:
my @handlers = @{ $req->get_handlers('PerlResponseHandler') || [] };
=head2 get_status_line
Return the C<Status-Line> for a given status code (excluding the HTTP-Version field), by calling L<Apache2::RequestRec/status_line>
For example:
print( $req->get_status_line( 400 ) );
will print:
400 Bad Request
See also L</status_line>
=head2 global_request
Returns the L<Apache2::RequestRec> object made global with the proper directive in the Apache VirtualHost configuration.
This calls L<Apache2::RequestUtil/request> to retrieve this value.
( run in 0.642 second using v1.01-cache-2.11-cpan-39bf76dae61 )