Apache2-API
view release on metacpan or search on metacpan
lib/Apache2/API/Request.pm view on Meta::CPAN
See also L<main|/main>, which returns the main request object.
=head2 is_secure
Returns true (1) if the connection is made under ssl, i.e. of the environment variable C<HTTPS> is set to C<on>, other it returns false (0).
This is done by checking if the environment variable C<HTTPS> is set to C<on> or not.
=head2 json
Returns a L<JSON> object with the C<relaxed> attribute enabled so that it allows more relaxed C<JSON> data.
You can provide an optional hash or hash reference of properties to enable or disable:
my $J = $api->json( pretty => 1, relaxed => 1 );
Each property corresponds to one that is supported by L<JSON>
It also supports C<ordered>, C<order> and C<sort> as an alias to C<canonical>
=head2 keepalive
$status = $c->keepalive();
$status = $c->keepalive($new_status);
This method answers the question: Should the the connection be kept alive for another HTTP request after the current request is completed?
This sets or gets the status by calling L<Apache2::Connection/keepalive>
use Apache2::Const -compile => qw(:conn_keepalive);
# ...
my $c = $req->connection;
if ($c->keepalive == Apache2::Const::CONN_KEEPALIVE) {
# do something
}
elsif ($c->keepalive == Apache2::Const::CONN_CLOSE) {
# do something else
}
elsif ($c->keepalive == Apache2::Const::CONN_UNKNOWN) {
# do yet something else
}
else {
# die "unknown state";
}
Notice that new states could be added later by Apache, so your code should make no assumptions and do things only if the desired state matches.
The method does not return true or false, but one of the states which can be compared against Apache constants (C<:conn_keepalive constants>).
See L<Apache2::Connection> for more information.
=head2 keepalives
my $served = $req->connection->keepalives();
my $served = $req->connection->keepalives( $new_served );
This returns an integer representing how many requests were already served over the current connection.
This method calls L<Apache2::Connection/keepalives>
This method is only relevant for keepalive connections. The core connection output filter C<ap_http_header_filter> increments this value when the response headers are sent and it decides that the connection should not be closed (see "ap_set_keepalive...
If you send your own set of HTTP headers with C<< $req->assbackwards >>, which includes the C<Keep-Alive> HTTP response header, you must make sure to increment the C<keepalives> counter.
See L<Apache2::Connection> for more information.
=head2 languages
This will check the C<Accept-Languages> HTTP headers and derive a list of priority ordered user preferred languages and return an L<array object|Module::Generic::Array>.
See also the L</preferred_language> method.
=head2 length
Returns an integer representing the length in bytes of the request body, by calling L<Apache2::RequestRec/bytes_sent>
=head2 local_addr
Returns our server local address as a L<APR::SockAddr> object, by calling L<Apache2::Connection/local_addr>
my $local_sock_addr = $req->connection->local_addr;
my $port = $local_sock_addr->port;
my $ip = $local_sock_addr->ip_get; # e.g.: 192.168.1.2
=head2 local_host
Used for C<ap_get_server_name> when C<UseCanonicalName> is set to C<DNS> (ignores setting of HostnameLookups)
This calls L<Apache2::Connection/local_host>
Better to use the L</server_name> instead.
=head2 local_ip
Return our server IP address as string, by calling L<Apache2::Connection/local_ip>
=head2 location
Get the path of the <Location> section from which the current C<Perl*Handler> is being called.
This calls L<Apache2::RequestUtil/location>
Returns a string.
=head2 log
$req->log->emerg( "Urgent message." );
$req->log->alert( "Alert!" );
$req->log->crit( "Critical message." );
$req->log->error( "Error message." );
$req->log->warn( "Warning..." );
$req->log->notice( "You should know." );
$req->log->info( "This is for your information." );
$req->log->debug( "This is debugging message." );
Returns a L<Apache2::Log::Request> object.
=head2 log_error
Returns the value from L<Apache2::Request/log_error> by passing it whatever arguments were received.
lib/Apache2/API/Request.pm view on Meta::CPAN
=head2 unparsed_uri
The URI without any parsing performed.
If for example the request was:
GET /foo/bar/my_path_info?args=3 HTTP/1.0
C<< $req->uri >> returns:
/foo/bar/my_path_info
whereas C<< $req->unparsed_uri >> returns:
/foo/bar/my_path_info?args=3
=head2 uploads
Returns an L<array object|Module::Generic::Array> of L<Apache2::API::Request::Upload> objects.
=head2 uri
Returns a L<URI> object representing the full uri of the request.
This is different from the original L<Apache2::RequestRec> which only returns the path portion of the URI.
So, to get the path portion using our L</uri> method, one would simply do C<< $req->uri->path() >>
This L<URI> object is built using L<Apache2::RequestUtil/get_server_name> for the C<host>, L<Apache2::RequestUtil/get_server_port> for the port number, and the scheme is C<https> if the port is C<443>, otherwise C<http>. It is followed then by the pa...
=head2 url_decode
This is merely a convenient pointer to L</decode>
=head2 url_encode
This is merely a convenient pointer to L</encode>
=head2 user
Get the user name, if an authentication process was successful. Or set it, by calling L<Apache2::RequestRec/user>
For example, let's print the username passed by the client:
my( $res, $sent_pw ) = $req->get_basic_auth_pw;
return( $res ) if( $res != Apache2::Const::OK );
print( "User: ", $req->user );
=head2 user_agent
Returns the user agent, ie the browser signature as provided in the request headers received under the HTTP header C<User-Agent>
=head2 _find_bin( string )
Given a binary, this will search for it in the path.
=head2 _try( object type, method name, @_ )
Given an object type, a method name and optional parameters, this attempts to call it.
Apache2 methods are designed to die upon error, whereas our model is based on returning C<undef> and setting an exception with L<Module::Generic::Exception>, because we believe that only the main program should be in control of the flow and decide wh...
=head1 AUTHOR
Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
=head1 SEE ALSO
L<Apache2::Request>, L<Apache2::RequestRec>, L<Apache2::RequestUtil>
=head1 COPYRIGHT & LICENSE
Copyright (c) 2023 DEGUEST Pte. Ltd.
You can use, copy, modify and redistribute this package and associated
files under the same terms as Perl itself.
=cut
( run in 0.573 second using v1.01-cache-2.11-cpan-39bf76dae61 )