9 eval "use HTTP::Headers; use Params::Coerce; use URI;";
10 plan skip_all => "HTTP::Headers & Params::Coerce & URI required for this test" if $@;
23 use Moose::Util::TypeConstraints;
26 use Params::Coerce ();
31 => where { $_->isa('HTTP::Headers') };
35 => via { HTTP::Headers->new( @{ $_ } ) }
37 => via { HTTP::Headers->new( %{ $_ } ) };
41 => where { $_->isa('URI') };
45 => via { $_->isa('URI') ? $_ : Params::Coerce::coerce( 'URI', $_ ) }
47 => via { URI->new( $_, 'http' ) };
51 => where { /^HTTP\/[0-9]\.[0-9]$/ };
54 has 'base' => (is => 'rw', isa => 'Uri', coerce => 1);
55 has 'url' => (is => 'rw', isa => 'Uri', coerce => 1);
56 has 'method' => (is => 'rw', isa => 'Str');
57 has 'protocol' => (is => 'rw', isa => 'Protocol');
62 default => sub { HTTP::Headers->new }
67 isa_ok($r, 'Request');
70 my $header = $r->headers;
71 isa_ok($header, 'HTTP::Headers');
73 is($r->headers->content_type, '', '... got no content type in the header');
75 $r->headers( { content_type => 'text/plain' } );
77 my $header2 = $r->headers;
78 isa_ok($header2, 'HTTP::Headers');
79 isnt($header, $header2, '... created a new HTTP::Header object');
81 is($header2->content_type, 'text/plain', '... got the right content type in the header');
83 $r->headers( [ content_type => 'text/html' ] );
85 my $header3 = $r->headers;
86 isa_ok($header3, 'HTTP::Headers');
87 isnt($header2, $header3, '... created a new HTTP::Header object');
89 is($header3->content_type, 'text/html', '... got the right content type in the header');
91 $r->headers( HTTP::Headers->new(content_type => 'application/pdf') );
93 my $header4 = $r->headers;
94 isa_ok($header4, 'HTTP::Headers');
95 isnt($header3, $header4, '... created a new HTTP::Header object');
97 is($header4->content_type, 'application/pdf', '... got the right content type in the header');
101 } '... dies when it gets bad params';
105 is($r->protocol, undef, '... got nothing by default');
108 $r->protocol('HTTP/1.0');
109 } '... set the protocol correctly';
110 is($r->protocol, 'HTTP/1.0', '... got nothing by default');
113 $r->protocol('http/1.0');
114 } '... the protocol died with bar params correctly';