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 }
65 __PACKAGE__->meta->make_immutable(debug => 0);
69 isa_ok($r, 'Request');
72 my $header = $r->headers;
73 isa_ok($header, 'HTTP::Headers');
75 is($r->headers->content_type, '', '... got no content type in the header');
77 $r->headers( { content_type => 'text/plain' } );
79 my $header2 = $r->headers;
80 isa_ok($header2, 'HTTP::Headers');
81 isnt($header, $header2, '... created a new HTTP::Header object');
83 is($header2->content_type, 'text/plain', '... got the right content type in the header');
85 $r->headers( [ content_type => 'text/html' ] );
87 my $header3 = $r->headers;
88 isa_ok($header3, 'HTTP::Headers');
89 isnt($header2, $header3, '... created a new HTTP::Header object');
91 is($header3->content_type, 'text/html', '... got the right content type in the header');
93 $r->headers( HTTP::Headers->new(content_type => 'application/pdf') );
95 my $header4 = $r->headers;
96 isa_ok($header4, 'HTTP::Headers');
97 isnt($header3, $header4, '... created a new HTTP::Header object');
99 is($header4->content_type, 'application/pdf', '... got the right content type in the header');
103 } '... dies when it gets bad params';
107 is($r->protocol, undef, '... got nothing by default');
110 $r->protocol('HTTP/1.0');
111 } '... set the protocol correctly';
112 is($r->protocol, 'HTTP/1.0', '... got nothing by default');
115 $r->protocol('http/1.0');
116 } '... the protocol died with bar params correctly';