Apache2-API
view release on metacpan or search on metacpan
lib/Apache2/API/Response.pm view on Meta::CPAN
sub status { return( shift->_try( '_request', 'status', @_ ) ); }
sub status_line { return( shift->_try( '_request', 'status_line', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Strict-Transport-Security>
sub strict_transport_security { return( shift->_set_get_one( 'Strict-Transport-Security', @_ ) ); }
sub subprocess_env { return( shift->_try( '_request', 'subprocess_env' ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Timing-Allow-Origin>
sub timing_allow_origin { return( shift->_set_get_multi( 'Timing-Allow-Origin', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer>
sub trailer { return( shift->_set_get_one( 'Trailer', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Transfer-Encoding>
sub transfer_encoding { return( shift->_set_get_one( 'Transfer-Encoding', @_ ) ); }
sub unescape { return( URI::Escape::uri_unescape( @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Upgrade>
sub upgrade { return( shift->_set_get_multi( 'Upgrade', @_ ) ); }
sub update_mtime { return( shift->_try( '_request', 'update_mtime', @_ ) ); }
sub uri_escape { return( shift->escape( @_ ) ); }
sub uri_unescape { return( shift->unescape( @_ ) ); }
sub url_decode { return( shift->decode( @_ ) ); }
sub url_encode { return( shift->encode( @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Vary>
sub vary { return( shift->_set_get_multi( 'Vary', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Via>
sub via { return( shift->_set_get_multi( 'Via', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Want-Digest>
sub want_digest { return( shift->_set_get_multi( 'Want-Digest', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Warning>
sub warning { return( shift->_set_get_one( 'Warning', @_ ) ); }
# e.g. $cnt = $r->write($buffer);
# $cnt = $r->write( $buffer, $len );
# $cnt = $r->write( $buffer, $len, $offset );
sub write { return( shift->_try( '_request', 'write', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate>
sub www_authenticate { return( shift->_set_get_one( 'WWW-Authenticate', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>
sub x_content_type_options { return( shift->_set_get_one( 'X-Content-Type-Options', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control>
sub x_dns_prefetch_control { return( shift->_set_get_one( 'X-DNS-Prefetch-Control', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>
sub x_frame_options { return( shift->_set_get_one( 'X-Frame-Options', @_ ) ); }
# <https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection>
sub x_xss_protection { return( shift->_set_get_one( 'X-XSS-Protection', @_ ) ); }
sub _headers
{
my $self = shift( @_ );
my $type = shift( @_ ) ||
return( $self->error({
message => "No header type was specified.",
want => [qw( hash )],
}) );
my $req = $self->_request ||
return( $self->error({
message => "No Apache2::RequestRec found!",
want => [qw( hash )],
}) );
my $code = $req->can( $type ) ||
return( $self->error({
message => "Header type '$type' is unsupported by Apache2::RequestRec",
want => [qw( hash )],
}) );
my $apr = $code->( $req ) ||
return( $self->error({
message => "Could not get an APR::Table object from Apache2::RequestRec->${type}",
want => [qw( hash )],
}) );
if( !$self->_is_a( $apr => 'APR::Table' ) )
{
return( $self->error({
message => "Object retrieved from Apache2::RequestRec->${type} is not an APR::Table object.",
want => [qw( hash )],
}) );
}
if( scalar( @_ ) && !( @_ % 2 ) )
{
for( my $i = 0; $i < scalar( @_ ); $i += 2 )
{
if( !defined( $_[ $i + 1 ] ) )
{
$apr->unset( $_[ $i ] );
}
else
{
$apr->set( $_[ $i ] => $_[ $i + 1 ] );
}
}
}
elsif( scalar( @_ ) )
{
return( $apr->get( shift( @_ ) ) );
}
else
{
return( $apr );
}
}
sub _request { return( shift->request->request ); }
lib/Apache2/API/Response.pm view on Meta::CPAN
$resp->no_cache(1);
$resp->no_local_copy(1);
$resp->print( @some_data );
$resp->printf( $template, $param1, $param2 );
my $puts = $resp->puts;
my $rv = $resp->redirect( $uri );
# Referrer-Policy
my $policy = $resp->referrer_policy;
my $r = $resp->request;
# Retry-After
my $retry_after = $resp->retry_after;
$resp->rflush;
$resp->send_cgi_header;
$resp->sendfile( $filename, $offset, $len );
$resp->sendfile( $filename );
# Server
my $server = $resp->server;
my $server_timing = $resp->server_timing;
$resp->set_content_length(1024);
# Set-Cookie
$resp->set_cookie( $cookie );
$resp->set_last_modified;
$resp->set_keepalive(1);
my $socket = $resp->socket;
my $sourcemap = $resp->sourcemap;
my $status = $resp->status;
my $status_line = $resp->status_line;
# Strict-Transport-Security
my $policy = $resp->strict_transport_security;
# APR::Table object
my $env = $resp->subprocess_env;
# Timing-Allow-Origin
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 );
# WWW-Authenticate
my $auth = $resp->www_authenticate;
# X-Content-Type-Options
my $opt = $resp->x_content_type_options;
# X-DNS-Prefetch-Control
my $proto = $resp->x_dns_prefetch_control;
# X-Frame-Options
my $opt = $resp->x_frame_options;
# X-XSS-Protection
my $xss = $resp->x_xss_protection;
=head1 VERSION
v0.2.0
=head1 DESCRIPTION
The purpose of this module is to provide an easy access to various method to process and manipulate incoming request.
This is designed to work under modperl.
Normally, one would need to know which method to access across various Apache2 mod perl modules, which makes development more time consuming and even difficult, because of the scattered documentation and even sometime outdated.
This module alleviate this problem by providing all the necessary methods in one place. Also, at the contrary of C<Apache2> modules suit, all the methods here are die safe. When an error occurs, it will always return undef() and the error will be abl...
Fo its alter ego to manipulate outgoing HTTP response, use the L<Apache2::API::Response> module.
=head1 CONSTRUCTORS
=head2 new
This initiates the package and take the following parameters:
=over 4
=item * C<checkonly>
If true, it will not perform the initialisation it would usually do under modperl.
=item * C<debug>
Optional. If set with a positive integer, this will activate verbose debugging message
=item * C<request>
This is a required parameter to be sent with a value set to a L<Apache2::RequestRec> object
=back
=head1 METHODS
=head2 allow_credentials
Sets or gets the HTTP header field C<Access-Control-Allow-Credentials>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials>
=head2 allow_headers
Sets or gets the HTTP header field C<Access-Control-Allow-Credentials>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers>
=head2 allow_methods
Sets or gets the HTTP header field C<Access-Control-Allow-Methods>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Methods>
lib/Apache2/API/Response.pm view on Meta::CPAN
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>
=head2 via
Sets or gets the HTTP header field C<Via>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Via>
=head2 want_digest
Sets or gets the HTTP header field C<Want-Digest>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Want-Digest>
=head2 warning
Sets or gets the HTTP header field C<Warning>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Warning>
=head2 write
Send partial string to the client, by calling L<Apache2::RequestIO/write>
$cnt = $resp->write( $buffer );
$cnt = $resp->write( $buffer, $len );
$cnt = $resp->write( $buffer, $len, $offset );
It returns How many bytes were sent (or buffered).
See L<Apache2::RequestIO> for more information.
=head2 www_authenticate
Sets or gets the HTTP header field C<WWW-Authenticate>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/WWW-Authenticate>
=head2 x_content_type_options
Sets or gets the HTTP header field C<X-Content-Type-Options>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Content-Type-Options>
=head2 x_dns_prefetch_control
Sets or gets the HTTP header field C<X-DNS-Prefetch-Control>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-DNS-Prefetch-Control>
=head2 x_frame_options
Sets or gets the HTTP header field C<X-Frame-Options>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options>
=head2 x_xss_protection
Sets or gets the HTTP header field C<X-XSS-Protection>
See L<https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-XSS-Protection>
=head2 _request
Returns the embedded L<Apache2::RequestRec>
=head2 _set_get_multi
$self->_set_get_multi( 'SomeHeader' => $some_value );
Sets or gets a header with multiple values. The value provided for the header can be either an array reference and it will be used as is (after being copied), or a regular string, which will be converted into an array reference by splitting it by com...
If the value is undefined, it will remove the corresponding header.
$self->_set_get_multi( 'SomeHeader' => undef() );
If no value is provided, it returns the current value for this header as a L<Module::Generic::Array> object.
=head2 _set_get_one
Sets or gets a header with the provided value. If the value is undefined, the header will be removed.
If no value is provided, it returns the current value as an array object (L<Module::Generic::Array>) or as a scalar object (L<Module::Generic::Scalar>) if it is not a reference.
=head2 _try( object accessor, method, [ arguments ] )
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 1.043 second using v1.01-cache-2.11-cpan-df04353d9ac )