APR-HTTP-Headers-Compat
view release on metacpan or search on metacpan
t/compat/base/headers.t view on Meta::CPAN
$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:" );
is( $h->authorization_basic, "u:p" );
is( j( $h->authorization_basic ), "u|p" );
is( $h->authorization, "Basic dTpw" );
is( eval { $h->authorization_basic( "u2:p" ) }, undef );
ok( $@ );
is( j( $h->authorization_basic ), "u|p" );
is( $h->proxy_authorization_basic( "u2", "p2" ), undef );
is( j( $h->proxy_authorization_basic ), "u2|p2" );
is( $h->proxy_authorization, "Basic dTI6cDI=" );
is( $h->as_string, <<EOT);
Authorization: Basic dTpw
Proxy-Authorization: Basic dTI6cDI=
Proxy-Authenticate: bar
WWW-Authenticate: bar
EOT
#---- old tests below -----
$h = mk(
mime_version => "1.0",
content_type => "text/html"
);
$h->header( URI => "http://www.oslonett.no/" );
is( $h->header( "MIME-Version" ), "1.0" );
is( $h->header( 'Uri' ), "http://www.oslonett.no/" );
$h->header(
"MY-header" => "foo",
"Date" => "somedate",
"Accept" => [ "text/plain", "image/*" ],
);
$h->push_header( "accept" => "audio/basic" );
is( $h->header( "date" ), "somedate" );
my @accept = $h->header( "accept" );
is( @accept, 3 );
$h->remove_header( "uri", "date" );
my $str = $h->as_string;
my $lines = ( $str =~ tr/\n/\n/ );
is( $lines, 6 );
$h2 = $h->clone;
$h->header( "accept", "*/*" );
$h->remove_header( "my-header" );
@accept = $h2->header( "accept" );
is( @accept, 3 );
@accept = $h->header( "accept" );
is( @accept, 1 );
# Check order of headers, but first remove this one
$h2->remove_header( 'mime_version' );
# and add this general header
$h2->header( Connection => 'close' );
my @x = ();
$h2->scan( sub { push( @x, shift ); } );
is( join( ";", @x ),
"Connection;Accept;Accept;Accept;Content-Type;MY-Header" );
( run in 1.174 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )