view release on metacpan or search on metacpan
Given some data, this will decode it using base64 algorithm. It uses
"decode" in APR::Base64 in the background.
decode_json( $data )
This decode from utf8 some data into a perl structure using JSON
If an error occurs, it will return undef and set an exception that can
be accessed with the error method.
decode_url( $string )
Given a url-encoded string, this returns the decoded string using
"decode" in APR::Request
decode_utf8( $data )
Decode some data from ut8 into perl internal utf8 representation using
Encode
If an error occurs, it will return undef and set an exception that can
be accessed with the error method.
encode_base64( $data )
Given some data, this will decode it using base64 algorithm. It uses ["decode" in APR::Base64](https://metacpan.org/pod/APR%3A%3ABase64#decode) in the background.
## decode\_json( $data )
This decode from utf8 some data into a perl structure using [JSON](https://metacpan.org/pod/JSON)
If an error occurs, it will return undef and set an exception that can be accessed with the [error](https://metacpan.org/pod/Module%3A%3AGeneric#error) method.
## decode\_url( $string )
Given a url-encoded string, this returns the decoded string using ["decode" in APR::Request](https://metacpan.org/pod/APR%3A%3ARequest#decode)
## decode\_utf8( $data )
Decode some data from ut8 into perl internal utf8 representation using [Encode](https://metacpan.org/pod/Encode)
If an error occurs, it will return undef and set an exception that can be accessed with the [error](https://metacpan.org/pod/Module%3A%3AGeneric#errir) method.
## encode\_base64( $data )
Given some data, this will encode it using base64 algorithm. It uses ["encode" in APR::Base64](https://metacpan.org/pod/APR%3A%3ABase64#encode).
lib/Apache2/API.pm view on Meta::CPAN
return( $api->bailout({
message => "Oops",
code => Apache2::Const::BAD_REQUEST,
public_message => "An unexpected error occurred.",
}) );
# or
return( $api->bailout( @some_reasons ) );
# 100kb
$api->compression_threshold(102400);
my $decoded = $api->decode_base64( $b64_string );
my $ref = $api->decode_json( $json_data );
my $decoded = $api->decode_url;
my $perl_utf8 = $api->decode_utf8( $data );
my $b64_string = $api->encode_base64( $data );
my $json_data = $api->encode_json( $ref );
my $encoded = $api->encode_url( $uri );
my $utf8 = $api->encode_utf8( $data );
my $uuid = $api->generate_uuid;
my $auth = $api->get_auth_bearer;
my $handlers = $api->get_handlers;
my $dt = $api->header_datetime( $http_datetime );
my $bool = $api->is_perl_option_enabled;
lib/Apache2/API.pm view on Meta::CPAN
Given some data, this will decode it using base64 algorithm. It uses L<APR::Base64/decode> in the background.
=head2 decode_json( $data )
This decode from utf8 some data into a perl structure using L<JSON>
If an error occurs, it will return undef and set an exception that can be accessed with the L<error|Module::Generic/error> method.
=head2 decode_url( $string )
Given a url-encoded string, this returns the decoded string using L<APR::Request/decode>
=head2 decode_utf8( $data )
Decode some data from ut8 into perl internal utf8 representation using L<Encode>
If an error occurs, it will return undef and set an exception that can be accessed with the L<error|Module::Generic/errir> method.
=head2 encode_base64( $data )
Given some data, this will encode it using base64 algorithm. It uses L<APR::Base64/encode>.
lib/Apache2/API/Query.pm view on Meta::CPAN
=head1 VERSION
v0.1.0
=head1 DESCRIPTION
This module simply inherits from L<URI::Query> and changed 2 subroutines to make them compliant with utf8 strings being fed to L<URI::Query>.
The 2 subroutines modified are: B<_parse_qs> and B<_init_from_arrayref>
L<URI::Query> does, otherwise, a very good job, but does not utf8 decode data from query strings after having url decoded it.
When, encoding data as query string, it does utf8 encode it before url encoding them, but not the other way around. So this module provides a temporary fix and is likely to be removed in the future when the module maintainer will have fixed this.
The rest below is taken from L<URI::Query> documentation and is copied here for convenience.
=head2 CONSTRUCTOR
Apache2::API::Query objects can be constructed from scalar query strings ('foo=1&bar=2&bar=3'), from a hashref which has parameters as keys, and values either as scalars or arrayrefs of scalars (to handle the case of parameters with multiple values e...
# Constructor - using a GET query string
lib/Apache2/API/Request.pm view on Meta::CPAN
# 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
lib/Apache2/API/Request.pm view on Meta::CPAN
my $dt = $req->time2datetime( $time );
say $req->time2str( $seconds );
# text/plain
my $type = $req->type;
my $raw = $req->unparsed_uri;
# Apache2::API::Request::Params
my $uploads = $req->uploads;
my $uri = $req->uri;
my $decoded = $req->url_decode( $url );
my $encoded = $req->url_encode( $url );
my $user = $req->user;
my $agent = $req->user_agent;
=head1 VERSION
v0.2.1
=head1 DESCRIPTION
lib/Apache2/API/Request.pm view on Meta::CPAN
Get the details from the basic authentication, by calling L<Apache2::Access/get_basic_auth_pw>
It returns:
=over 4
=item 1. the value of an Apache constant
This would be C<Apache2::Const::OK> if the password value is set (and assured a correct value in L</user>); otherwise it returns an error code, either C<Apache2::Const::HTTP_INTERNAL_SERVER_ERROR> if things are really confused, C<Apache2::Const::HTTP...
=item 2. the password as set in the headers (decoded)
=back
Note that if C<AuthType> is not set, L<Apache2::Access/get_basic_auth_pw> first sets it to C<Basic>.
=head2 body
Returns an L<APR::Request::Param::Table|APR::Request::Param> object containing the C<POST> data parameters of the L<Apache2::Request> object.
my $body = $req->body;
lib/Apache2/API/Request.pm view on Meta::CPAN
This is just an example and not a recommandation. Your mileage may vary.
=head2 datetime
Returns a new L<Apache2::API::DateTime> object, which is used to parse and format dates for HTTP.
See L<Apache2::API/parse_datetime> and L<Apache2::API/format_datetime>
=head2 decode
Given a url-encoded string, this returns the decoded string, by calling L<APR::Request/decode>
This uses L<APR::Request> XS method.
See also L<rfc3986|https://datatracker.ietf.org/doc/html/rfc3986>
=head2 discard_request_body
my $rc = $req->discard_request_body;
In C<HTTP/1.1>, any method can have a body. However, most C<GET> handlers would not know what to do with a request body if they received one. This helper routine tests for and reads any message body in the request, simply discarding whatever it recei...
lib/Apache2/API/Request.pm view on Meta::CPAN
my $path_info = $req->path_info();
my $prev_path_info = $req->path_info( $path_info );
Get or set the C<PATH_INFO>, what is left in the path after the C<< URI --> filename >> translation, by calling L<Apache2::RequestRec/path_info>
Return a string as the current value.
=head2 payload
Returns the JSON data decoded into a perl structure. This is set at object initiation phase and calls the L</data> method to read the incoming data and decoded it into perl internal utf8.
=head2 per_dir_config
Get the dir config vector, by calling L<Apache2::RequestRec/per_dir_config>. Returns a L<Apache2::ConfVector> object.
For an in-depth discussion, refer to the Apache Server Configuration Customization in Perl chapter.
=head2 pnotes
Share Perl variables between Perl HTTP handlers, using L<Apache2::RequestUtil/pnotes>.
lib/Apache2/API/Response.pm view on Meta::CPAN
$resp->cookie_replace( $cookie );
$resp->cookie_set( $cookie );
# Cross-Origin-Embedder-Policy
my $policy = $resp->cross_origin_embedder_policy;
# Cross-Origin-Opener-Policy
my $policy = $resp->cross_origin_opener_policy;
# Cross-Origin-Resource-Policy
my $policy = $resp->cross_origin_resource_policy;
my $cspro = $resp->cspro;
$resp->custom_response( Apache2::Const::AUTH_REQUIRED, "Authenticate please" );
my $decoded = $resp->decode( $string );
# Digest
my $digest = $resp->digest;
my $encoded = $resp->encode( $string );
# APR::Table object
my $env = $resp->env;
my $headers = $resp->err_headers;
my $headers = $resp->err_headers_out;
my $escaped = $resp->escape( $string );
my $etag = $resp->etag;
# Expires
lib/Apache2/API/Response.pm view on Meta::CPAN
my $origin = $resp->timing_allow_origin;
# Trailer
my $trailerv = $resp->trailer;
my $enc = $resp->transfer_encoding;
my $unescape = $resp->unescape( $string );
# Upgrade
my $upgrade = $resp->upgrade;
$resp->update_mtime( $seconds );
my $uri = $resp->uri_escape( $uri );
my $uri = $resp->uri_unescape( $uri );
my $decoded = $resp->url_decode( $uri );
my $encoded = $resp->url_encode( $uri );
# Vary
my $vary = $resp->vary;
# Via
my $via = $resp->via;
# Want-Digest
my $want = $resp->want_digest;
# Warning
my $warn = $resp->warning;
$resp->write( $buffer, $len, $offset );
lib/Apache2/API/Response.pm view on Meta::CPAN
PerlAccessHandler MyApache2::MyShop::access
PerlResponseHandler MyApache2::MyShop::response
</Location>
When squirrels cannot run any more, the handler will return C<403>, with the custom message:
It is siesta time, please try later
=head2 decode
Given a url-encoded string, this returns the decoded string
This uses L<APR::Request> XS method.
=head2 digest
Sets or gets the HTTP header field C<Digest>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Digest>
=head2 encode
lib/Apache2/API/Response.pm view on Meta::CPAN
=head2 uri_escape
Provided with a string and this uses L<URI::Escape> to return an uri-escaped string.
=head2 uri_unescape
Provided with an uri-escaped string and this will decode it and return its original string, by calling L<URI::Escape/uri_unescape>
=head2 url_decode
Provided with an url-encoded string and this will return its decoded version, by calling L<APR::Request/decode>
=head2 url_encode
Provided with a string and this will return an url-encoded version, by calling L<APR::Request/encode>
=head2 vary
Sets or gets the HTTP header field C<Vary>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary>
&simple_test({ target => 'api', name => 'auth', code => Apache2::Const::HTTP_OK, headers => [Authorization => "Bearer: $jwt"] });
&simple_test({ target => 'api', name => 'header_datetime', code => Apache2::Const::HTTP_OK });
&simple_test({ target => 'api', name => 'is_perl_option_enabled', code => Apache2::Const::HTTP_OK });
&simple_test({ target => 'api', name => 'json', code => Apache2::Const::HTTP_OK });
$resp = &make_request( api => 'reply' );
my $j = JSON->new;
my $content = $resp->decoded_content;
diag( "test 'reply' decoded_content is '$content'" ) if( $DEBUG );
my $ref;
eval
{
$ref = $j->decode( $content );
};
ok( ref( $ref ) eq 'HASH', 'reply -> JSON decoded content is an hash reference' );
is( $resp->code, Apache2::Const::HTTP_OK, 'reply code' );
is( $ref->{message}, 'ok', 'reply message' );
&simple_test({ target => 'api', name => 'server', code => Apache2::Const::HTTP_OK });
&simple_test({ target => 'api', name => 'server_version', code => Apache2::Const::HTTP_OK });
};
subtest 'request' => sub
{