HTTP-Promise
view release on metacpan or search on metacpan
t/13.header_fields.t view on Meta::CPAN
};
subtest 'content-type' => sub
{
use ok( 'HTTP::Promise::Headers::ContentType' );
my $str = q{text/html; charset=UTF-8};
my $h = HTTP::Promise::Headers::ContentType->new( $str );
is( "$h", $str );
is( $h->type, 'text/html' );
is( $h->charset, 'UTF-8' );
$str = q{application/octet-stream};
$h = HTTP::Promise::Headers::ContentType->new( $str );
is( "$h", $str );
is( $h->type, 'application/octet-stream' );
$str = q{multipart/form-data; boundary=something};
$h = HTTP::Promise::Headers::ContentType->new( $str );
is( "$h", $str );
is( $h->type, 'multipart/form-data' );
is( $h->boundary, 'something' );
$str = q{application/x-www-form-urlencoded};
$h = HTTP::Promise::Headers::ContentType->new( $str );
is( "$h", $str );
is( $h->type, 'application/x-www-form-urlencoded' );
$str = q{multipart/byteranges};
$h = HTTP::Promise::Headers::ContentType->new( $str );
is( "$h", $str );
is( $h->type, 'multipart/byteranges' );
$h = HTTP::Promise::Headers::ContentType->new;
$h->type( 'text/plain' );
$h->charset( 'utf-8' );
is( "$h", 'text/plain; charset=utf-8' );
};
subtest 'expect-ct' => sub
{
use ok( 'HTTP::Promise::Headers::ExpectCT' );
my $str = q{max-age=86400, enforce, report-uri="https://foo.example.com/report"};
my $h = HTTP::Promise::Headers::ExpectCT->new( $str );
is( "$h", $str );
is( $h->max_age, 86400 );
is( $h->enforce, 1 );
is( $h->report_uri, 'https://foo.example.com/report' );
};
subtest 'forwarded' => sub
{
use ok( 'HTTP::Promise::Headers::Forwarded' );
my $str = q{for=192.0.2.60; proto=http; by=203.0.113.43};
my $h = HTTP::Promise::Headers::Forwarded->new( $str );
is( "$h", $str );
is( $h->for, '192.0.2.60' );
is( $h->proto, 'http' );
is( $h->by, '203.0.113.43' );
};
subtest 'keep-alive' => sub
{
use ok( 'HTTP::Promise::Headers::KeepAlive' );
my $str = q{timeout=5, max=1000};
my $h = HTTP::Promise::Headers::KeepAlive->new( $str );
is( "$h", $str );
is( $h->timeout, 5 );
is( $h->max, 1000 );
};
subtest 'link' => sub
{
use utf8;
use ok( 'HTTP::Promise::Headers::Link' );
my $str = q{<https://example.com>; rel=preconnect};
my $h = HTTP::Promise::Headers::Link->new( $str );
is( "$h", $str );
is( $h->link, 'https://example.com' );
is( $h->rel, 'preconnect' );
$h = HTTP::Promise::Headers::Link->new;
$h->link( 'https://dev.example.org' );
$h->rel( 'next' );
$h->title( 'å¥ã«', 'ja-JP' );
$h->anchor( '#baz' );
is( "$h" => q{<https://dev.example.org>; rel=next; title*=UTF-8'ja-JP'%E5%88%A5%E3%81%AB; anchor=#baz} );
};
subtest 'range' => sub
{
use ok( 'HTTP::Promise::Headers::Range' );
my $str = q{bytes=200-1000, 1001-2000, 2001-3000};
my $h = HTTP::Promise::Headers::Range->new( $str );
is( "$h", $str );
is( $h->ranges->first->start, 200 );
is( $h->ranges->first->end, 1000 );
is( $h->ranges->second->start, 1001 );
is( $h->ranges->second->end, 2000 );
is( $h->ranges->third->start, 2001 );
is( $h->ranges->third->end, 3000 );
$str = q{bytes=200-};
$h = HTTP::Promise::Headers::Range->new( $str );
is( "$h", $str );
is( $h->ranges->first->start, 200 );
is( $h->ranges->first->end, undef );
$str = q{bytes=-4321};
$h = HTTP::Promise::Headers::Range->new( $str );
is( "$h", $str );
is( $h->ranges->first->start, undef );
is( $h->ranges->first->end, 4321 );
};
subtest 'server-timing' => sub
{
use ok( 'HTTP::Promise::Headers::ServerTiming' );
my $str = q{cache; desc="Cache Read"; dur=23.2};
my $h = HTTP::Promise::Headers::ServerTiming->new( $str );
is( "$h", $str );
t/13.header_fields.t view on Meta::CPAN
is( "$h", q{max-age=63072000; preload} );
$h = HTTP::Promise::Headers::StrictTransportSecurity->new;
$h->include_subdomains(1);
$h->max_age(63072000);
$h->preload(1);
$h->property_boolean( 'something_else' => 1 );
is( "$h", q{includeSubDomains; max-age=63072000; preload; something_else} );
is( $h->max_age, 63072000 );
is( $h->preload, 1 );
};
subtest 'te' => sub
{
use ok( 'HTTP::Promise::Headers::TE' );
my $str = q{trailers, deflate;q=0.5};
my $h = HTTP::Promise::Headers::TE->new( $str );
is( "$h", $str );
my $e = $h->get( 'trailers' );
isa_ok( $e => ['HTTP::Promise::Field::QualityValue'] );
is( $e->element, 'trailers' );
is( $e->value, undef );
my $e2 = $h->get( 'deflate' );
isa_ok( $e2 => ['HTTP::Promise::Field::QualityValue'] );
is( $e2->element, 'deflate' );
is( $e2->value, 0.5 );
ok( $e2->value > $e->value );
ok( !( $e2->value < $e->value ) );
};
subtest 'want-digest' => sub
{
use ok( 'HTTP::Promise::Headers::WantDigest' );
my $str = q{SHA-512;q=0.3, sha-256;q=1, md5;q=0};
my $h = HTTP::Promise::Headers::WantDigest->new( $str );
is( "$h", $str );
my $e = $h->get( 'SHA-512' );
isa_ok( $e => ['HTTP::Promise::Field::QualityValue'] );
};
subtest "new_field" => sub
{
use ok( 'HTTP::Promise::Headers' );
my $h = HTTP::Promise::Headers->new;
my %tests = (
accept_encoding => 'HTTP::Promise::Headers::AcceptEncoding',
accept_language => 'HTTP::Promise::Headers::AcceptLanguage',
accept => 'HTTP::Promise::Headers::Accept',
altsvc => 'HTTP::Promise::Headers::AltSvc',
cache_control => 'HTTP::Promise::Headers::CacheControl',
clear_site_data => 'HTTP::Promise::Headers::ClearSiteData',
content_disposition => 'HTTP::Promise::Headers::ContentDisposition',
content_range => 'HTTP::Promise::Headers::ContentRange',
content_securit_ypolicy => 'HTTP::Promise::Headers::ContentSecurityPolicy',
content_security_policy_report_only => 'HTTP::Promise::Headers::ContentSecurityPolicyReportOnly',
content_type => 'HTTP::Promise::Headers::ContentType',
cookie => 'HTTP::Promise::Headers::Cookie',
expectct => 'HTTP::Promise::Headers::ExpectCT',
forwarded => 'HTTP::Promise::Headers::Forwarded',
generic => 'HTTP::Promise::Headers::Generic',
keepalive => 'HTTP::Promise::Headers::KeepAlive',
link => 'HTTP::Promise::Headers::Link',
range => 'HTTP::Promise::Headers::Range',
server_timing => 'HTTP::Promise::Headers::ServerTiming',
strict_transport_security => 'HTTP::Promise::Headers::StrictTransportSecurity',
te => 'HTTP::Promise::Headers::TE',
wantdigest => 'HTTP::Promise::Headers::WantDigest',
);
foreach( sort( keys( %tests ) ) )
{
my $f = $h->new_field( $_ ) || do
{
diag( "Failed instantiating an object for \"$_\": ", $h->error ) if( $DEBUG );
fail( $tests{ $_ } );
next;
};
isa_ok( $f, [ $tests{ $_ } ] );
}
};
done_testing();
__END__
( run in 1.071 second using v1.01-cache-2.11-cpan-71847e10f99 )