Apache2-API
view release on metacpan or search on metacpan
t/lib/Test/Apache2/API/Request.pm view on Meta::CPAN
package Test::Apache2::API::Request;
BEGIN
{
use strict;
use warnings;
use lib './lib';
use parent qw( Test::Apache2::Common );
use Apache2::Connection ();
use Apache2::Const -compile => qw( :common :http OK DECLINED );
use Apache2::RequestIO ();
use Apache2::RequestRec ();
# so we can get the request as a string
use Apache2::RequestUtil ();
use Apache::TestConfig;
use APR::URI ();
use Apache2::API;
use Scalar::Util;
# 2021-11-1T17:12:10+0900
use Test::Time time => 1635754330;
use constant HAS_SSL => ( $ENV{HTTPS} || ( defined( $ENV{SCRIPT_URI} ) && substr( lc( $ENV{SCRIPT_URI} ), 0, 5 ) eq 'https' ) ) ? 1 : 0;
};
use strict;
use warnings;
our $config = Apache::TestConfig->thaw->httpd_config;
our $port = $config->{vars}->{port} || 0;
sub aborted { return( shift->_test({ method => 'aborted', expect => 0, type => 'boolean' }) ); }
# text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
# application/json; version=1.0; charset=utf-8, text/javascript, */*
sub accept { return( shift->_test({ method => 'accept', expect => 'application/json; version=1.0; charset=utf-8, text/javascript, */*' }) ); }
# application/json; version=1.0; charset=utf-8
sub accept_charset { return( shift->_test({ method => 'accept_charset', expect => 'utf-8' }) ); }
# gzip, deflate;q=1.0, *;q=0.5
# gzip, deflate, br
sub accept_encoding { return( shift->_test({ method => 'accept_encoding', expect => 'gzip, deflate, br' }) ); }
sub accept_language { return( shift->_test({ method => 'accept_language', expect => 'en-GB,fr-FR;q=0.8,fr;q=0.6,ja;q=0.4,en;q=0.2' }) ); }
# application/json
sub accept_type { return( shift->_test({ method => 'accept_type', expect => 'application/json' }) ); }
# application/json; version=1.0; charset=utf-8
# sub accept_version { return( shift->_test({ method => 'accept_version', expect => '1.0' }) ); }
sub accept_version { return( shift->_test({ method => 'accept_version', expect => '1.0' }) ); }
# Check array reference of acceptable types:
# application/json; version=1.0; charset=utf-8, text/javascript, */*
sub acceptable { return( shift->_test({ method => 'acceptable', expect => sub
{
my $acceptable = shift( @_ );
my $opts = shift( @_ );
my $cnt = 0;
$opts->{log}->( "\$acceptable is '", ( $acceptable // 'undef' ), "' and contains: ", ( Scalar::Util::reftype( $acceptable ) eq 'ARRAY' ? join( ', ', @$acceptable ) : 'not an array' ) );
$cnt++ if( Scalar::Util::reftype( $acceptable // '' ) eq 'ARRAY' );
$cnt++ if( scalar( @$acceptable ) == 3 );
$cnt++ if( $acceptable->[0] eq 'application/json' && $acceptable->[1] eq 'text/javascript' && $acceptable->[2] eq '*/*' );
return( $cnt == 3 );
} }) ); }
# application/json; charset=utf-8; version=2, text/javascript, */*
sub acceptables { return( shift->_test({ method => 'acceptables', expect => sub
{
( run in 0.443 second using v1.01-cache-2.11-cpan-39bf76dae61 )