9 eval "use HTTP::Headers; use Params::Coerce; use URI;";
10 plan skip_all => "HTTP::Headers & Params::Coerce & URI required for this test" if $@;
19 use Moose::Util::TypeConstraints;
22 use Params::Coerce ();
25 class_type('HTTP::Headers');
27 coerce 'HTTP::Headers'
29 => via { HTTP::Headers->new( @{$_} ) }
31 => via { HTTP::Headers->new( %{$_} ) };
37 => via { $_->isa('URI')
39 : Params::Coerce::coerce( 'URI', $_ ); }
41 => via { URI->new( $_, 'http' ) };
45 => where { /^HTTP\/[0-9]\.[0-9]$/ };
47 has 'base' => ( is => 'rw', isa => 'URI', coerce => 1 );
48 has 'uri' => ( is => 'rw', isa => 'URI', coerce => 1 );
49 has 'method' => ( is => 'rw', isa => 'Str' );
50 has 'protocol' => ( is => 'rw', isa => 'Protocol' );
53 isa => 'HTTP::Headers',
55 default => sub { HTTP::Headers->new }
60 isa_ok($r, 'Request');
63 my $header = $r->headers;
64 isa_ok($header, 'HTTP::Headers');
66 is($r->headers->content_type, '', '... got no content type in the header');
68 $r->headers( { content_type => 'text/plain' } );
70 my $header2 = $r->headers;
71 isa_ok($header2, 'HTTP::Headers');
72 isnt($header, $header2, '... created a new HTTP::Header object');
74 is($header2->content_type, 'text/plain', '... got the right content type in the header');
76 $r->headers( [ content_type => 'text/html' ] );
78 my $header3 = $r->headers;
79 isa_ok($header3, 'HTTP::Headers');
80 isnt($header2, $header3, '... created a new HTTP::Header object');
82 is($header3->content_type, 'text/html', '... got the right content type in the header');
84 $r->headers( HTTP::Headers->new(content_type => 'application/pdf') );
86 my $header4 = $r->headers;
87 isa_ok($header4, 'HTTP::Headers');
88 isnt($header3, $header4, '... created a new HTTP::Header object');
90 is($header4->content_type, 'application/pdf', '... got the right content type in the header');
94 } '... dies when it gets bad params';
98 is($r->protocol, undef, '... got nothing by default');
101 $r->protocol('HTTP/1.0');
102 } '... set the protocol correctly';
103 is($r->protocol, 'HTTP/1.0', '... got nothing by default');
106 $r->protocol('http/1.0');
107 } '... the protocol died with bar params correctly';