Apache2-API

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  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 )

README.md  view on Meta::CPAN

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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

845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
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

959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
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

187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
=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

1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
# 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

1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
    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

1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
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

2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
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.
 
 
=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

2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
    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

780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
$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

873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
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

1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
         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>
 
 
=head2 encode

lib/Apache2/API/Response.pm  view on Meta::CPAN

1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
=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>
 

t/01.api.t  view on Meta::CPAN

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
    &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
{



( run in 0.297 second using v1.01-cache-2.11-cpan-ec4f86ec37b )