APR-HTTP-Headers-Compat
view release on metacpan or search on metacpan
t/compat/base/headers.t view on Meta::CPAN
is( $h->as_string, "Bar: 2\nFoo: 1\nFoo-Bar: 3\n" );
is( $h->as_string( ";" ), "Bar: 2;Foo: 1;Foo-Bar: 3;" );
is( $h->header( "Foo" ), 1 );
is( $h->header( "FOO" ), 1 );
is( j( $h->header( "foo" ) ), 1 );
is( $h->header( "foo-bar" ), 3 );
is( $h->header( "foo_bar" ), 3 );
is( $h->header( "Not-There" ), undef );
is( j( $h->header( "Not-There" ) ), "" );
is( eval { $h->header }, undef );
ok( $@ );
is( $h->header( "Foo", 11 ), 1 );
is( $h->header( "Foo", [ 1, 1 ] ), 11 );
is( $h->header( "Foo" ), "1, 1" );
is( j( $h->header( "Foo" ) ), "1|1" );
is( $h->header( foo => 11, Foo => 12, bar => 22 ), 2 );
is( $h->header( "Foo" ), "11, 12" );
is( $h->header( "Bar" ), 22 );
is( $h->header( "Bar", undef ), 22 );
is( j( $h->header( "bar", 22 ) ), "" );
$h->push_header( Bar => 22 );
is( $h->header( "Bar" ), "22, 22" );
$h->push_header( Bar => [ 23 .. 25 ] );
is( $h->header( "Bar" ), "22, 22, 23, 24, 25" );
is( j( $h->header( "Bar" ) ), "22|22|23|24|25" );
$h->clear;
$h->header( Foo => 1 );
is( $h->as_string, "Foo: 1\n" );
$h->init_header( Foo => 2 );
$h->init_header( Bar => 2 );
is( $h->as_string, "Bar: 2\nFoo: 1\n" );
$h->init_header( Foo => [ 2, 3 ] );
$h->init_header( Baz => [ 2, 3 ] );
is( $h->as_string, "Bar: 2\nBaz: 2\nBaz: 3\nFoo: 1\n" );
eval { $h->init_header( A => 1, B => 2, C => 3 ) };
ok( $@ );
is( $h->as_string, "Bar: 2\nBaz: 2\nBaz: 3\nFoo: 1\n" );
is( $h->clone->remove_header( "Foo" ), 1 );
is( $h->clone->remove_header( "Bar" ), 1 );
is( $h->clone->remove_header( "Baz" ), 2 );
is( $h->clone->remove_header( qw(Foo Bar Baz Not-There) ), 4 );
is( $h->clone->remove_header( "Not-There" ), 0 );
is( j( $h->clone->remove_header( "Foo" ) ), 1 );
is( j( $h->clone->remove_header( "Bar" ) ), 2 );
is( j( $h->clone->remove_header( "Baz" ) ), "2|3" );
is( j( $h->clone->remove_header( qw(Foo Bar Baz Not-There) ) ),
"1|2|2|3" );
is( j( $h->clone->remove_header( "Not-There" ) ), "" );
$h = mk(
allow => "GET",
content => "none",
content_type => "text/html",
content_md5 => "dummy",
content_encoding => "gzip",
content_foo => "bar",
last_modified => "yesterday",
expires => "tomorrow",
etag => "abc",
date => "today",
user_agent => "libwww-perl",
zoo => "foo",
);
is( $h->as_string, <<EOT);
Date: today
User-Agent: libwww-perl
ETag: abc
Allow: GET
Content-Encoding: gzip
Content-MD5: dummy
Content-Type: text/html
Expires: tomorrow
Last-Modified: yesterday
Content: none
Content-Foo: bar
Zoo: foo
EOT
$h2 = $h->clone;
is( $h->as_string, $h2->as_string );
is( $h->remove_content_headers->as_string, <<EOT);
Allow: GET
Content-Encoding: gzip
Content-MD5: dummy
Content-Type: text/html
Expires: tomorrow
Last-Modified: yesterday
Content-Foo: bar
EOT
is( $h->as_string, <<EOT);
Date: today
User-Agent: libwww-perl
ETag: abc
Content: none
Zoo: foo
EOT
# separate code path for the void context case, so test it as well
$h2->remove_content_headers;
is( $h->as_string, $h2->as_string );
$h->clear;
is( $h->as_string, "" );
undef( $h2 );
$h = mk;
is( $h->header_field_names, 0 );
is( j( $h->header_field_names ), "" );
$h = mk(
etag => 1,
foo => [ 2, 3 ],
content_type => "text/plain"
t/compat/base/headers.t view on Meta::CPAN
$h->scan( sub { push( @tmp, @_ ) } );
is( j( @tmp ), "ETag|1|Content-Type|text/plain|Foo|2|Foo|3" );
}
# CONVENIENCE METHODS
$h = mk;
is( $h->date, undef );
is( $h->date( time ), undef );
is( j( $h->header_field_names ), "Date" );
ok( $h->header( "Date" ) =~ /^[A-Z][a-z][a-z], \d\d .* GMT$/ );
{
my $off = time - $h->date;
ok( $off == 0 || $off == 1 );
}
if ( $] < 5.006 ) {
Test::skip( "Can't call variable method", 1 ) for 1 .. 13;
}
else {
# other date fields
for my $field (
qw(expires if_modified_since if_unmodified_since
last_modified)
) {
eval <<'EOT'; die $@ if $@;
is($h->$field, undef);
is($h->$field(time), undef);
ok((time - $h->$field) =~ /^[01]$/);
EOT
}
is( j( $h->header_field_names ),
"Date|If-Modified-Since|If-Unmodified-Since|Expires|Last-Modified"
);
}
$h->clear;
is( $h->content_type, "" );
is( $h->content_type( "text/html" ), "" );
is( $h->content_type, "text/html" );
is( $h->content_type( " TEXT / HTML " ), "text/html" );
is( $h->content_type, "text/html" );
is( j( $h->content_type ), "text/html" );
is( $h->content_type( "text/html;\n charSet = \"ISO-8859-1\"; Foo=1 " ),
"text/html" );
is( $h->content_type, "text/html" );
is( j( $h->content_type ),
"text/html|charSet = \"ISO-8859-1\"; Foo=1 " );
is( $h->header( "content_type" ),
"text/html;\n charSet = \"ISO-8859-1\"; Foo=1 " );
ok( $h->content_is_html );
ok( !$h->content_is_xhtml );
ok( !$h->content_is_xml );
$h->content_type( "application/xhtml+xml" );
ok( $h->content_is_html );
ok( $h->content_is_xhtml );
ok( $h->content_is_xml );
is( $h->content_type( "text/html;\n charSet = \"ISO-8859-1\"; Foo=1 " ),
"application/xhtml+xml" );
is( $h->content_encoding, undef );
is( $h->content_encoding( "gzip" ), undef );
is( $h->content_encoding, "gzip" );
is( j( $h->header_field_names ), "Content-Encoding|Content-Type" );
is( $h->content_language, undef );
is( $h->content_language( "no" ), undef );
is( $h->content_language, "no" );
is( $h->title, undef );
is( $h->title( "This is a test" ), undef );
is( $h->title, "This is a test" );
is( $h->user_agent, undef );
is( $h->user_agent( "Mozilla/1.2" ), undef );
is( $h->user_agent, "Mozilla/1.2" );
is( $h->server, undef );
is( $h->server( "Apache/2.1" ), undef );
is( $h->server, "Apache/2.1" );
is( $h->from( "Gisle\@ActiveState.com" ), undef );
ok( $h->header( "from", "Gisle\@ActiveState.com" ) );
is( $h->referer( "http://www.example.com" ), undef );
is( $h->referer, "http://www.example.com" );
is( $h->referrer, "http://www.example.com" );
is( $h->referer( "http://www.example.com/#bar" ),
"http://www.example.com" );
is( $h->referer, "http://www.example.com/" );
SKIP: {
skip "Can't store references" => 4;
require URI;
my $u = URI->new( "http://www.example.com#bar" );
$h->referer( $u );
is( $u->as_string, "http://www.example.com#bar" );
is( $h->referer->fragment, undef );
is( $h->referrer->as_string, "http://www.example.com" );
is( $h->as_string, <<EOT);
From: Gisle\@ActiveState.com
Referer: http://www.example.com
User-Agent: Mozilla/1.2
Server: Apache/2.1
Content-Encoding: gzip
Content-Language: no
Content-Type: text/html;
charSet = "ISO-8859-1"; Foo=1
Title: This is a test
EOT
}
$h->clear;
is( $h->www_authenticate( "foo" ), undef );
is( $h->www_authenticate( "bar" ), "foo" );
is( $h->www_authenticate, "bar" );
is( $h->proxy_authenticate( "foo" ), undef );
is( $h->proxy_authenticate( "bar" ), "foo" );
is( $h->proxy_authenticate, "bar" );
is( $h->authorization_basic, undef );
is( $h->authorization_basic( "u" ), undef );
is( $h->authorization_basic( "u", "p" ), "u:" );
( run in 0.613 second using v1.01-cache-2.11-cpan-39bf76dae61 )