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 ();
27 => where { $_->isa('HTTP::Headers') };
31 => via { HTTP::Headers->new( @{ $_ } ) }
33 => via { HTTP::Headers->new( %{ $_ } ) };
37 => where { $_->isa('URI') };
41 => via { $_->isa('URI') ? $_ : Params::Coerce::coerce( 'URI', $_ ) }
43 => via { URI->new( $_, 'http' ) };
47 => where { /^HTTP\/[0-9]\.[0-9]$/ };
50 has 'base' => (is => 'rw', isa => 'Uri', coerce => 1);
51 has 'url' => (is => 'rw', isa => 'Uri', coerce => 1);
52 has 'method' => (is => 'rw', isa => 'Str');
53 has 'protocol' => (is => 'rw', isa => 'Protocol');
58 default => sub { HTTP::Headers->new }
61 __PACKAGE__->meta->make_immutable(debug => 0);
65 isa_ok($r, 'Request');
68 my $header = $r->headers;
69 isa_ok($header, 'HTTP::Headers');
71 is($r->headers->content_type, '', '... got no content type in the header');
73 $r->headers( { content_type => 'text/plain' } );
75 my $header2 = $r->headers;
76 isa_ok($header2, 'HTTP::Headers');
77 isnt($header, $header2, '... created a new HTTP::Header object');
79 is($header2->content_type, 'text/plain', '... got the right content type in the header');
81 $r->headers( [ content_type => 'text/html' ] );
83 my $header3 = $r->headers;
84 isa_ok($header3, 'HTTP::Headers');
85 isnt($header2, $header3, '... created a new HTTP::Header object');
87 is($header3->content_type, 'text/html', '... got the right content type in the header');
89 $r->headers( HTTP::Headers->new(content_type => 'application/pdf') );
91 my $header4 = $r->headers;
92 isa_ok($header4, 'HTTP::Headers');
93 isnt($header3, $header4, '... created a new HTTP::Header object');
95 is($header4->content_type, 'application/pdf', '... got the right content type in the header');
99 } '... dies when it gets bad params';
103 is($r->protocol, undef, '... got nothing by default');
106 $r->protocol('HTTP/1.0');
107 } '... set the protocol correctly';
108 is($r->protocol, 'HTTP/1.0', '... got nothing by default');
111 $r->protocol('http/1.0');
112 } '... the protocol died with bar params correctly';