X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FRequest.pm;h=d1614a30857d4ac02423b776408fad391c1e9b12;hp=cf695ffeb9cf4c175ed6b1b84fb1fa8c4eb4110d;hb=d5f4b4343c1fbca2dac90249c74466a80f79cd5a;hpb=2f498a7ee1e99938c3684604336d99488c9d6499 diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index cf695ff..d1614a3 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -28,7 +28,23 @@ has _read_length => ( is => 'ro', has action => (is => 'rw'); has address => (is => 'rw'); has arguments => (is => 'rw', default => sub { [] }); -has cookies => (is => 'rw', default => sub { {} }); +has cookies => (is => 'ro', builder => 'prepare_cookies', lazy => 1); + +=head2 $self->prepare_cookies($c) + +Parse cookies from header. Sets a L object. + +=cut + +sub prepare_cookies { + my ( $self ) = @_; + + if ( my $header = $self->header('Cookie') ) { + return { CGI::Simple::Cookie->parse($header) }; + } + {}; +} + has query_keywords => (is => 'rw'); has match => (is => 'rw'); has method => (is => 'rw'); @@ -42,11 +58,29 @@ has headers => ( is => 'rw', isa => 'HTTP::Headers', handles => [qw(content_encoding content_length content_type header referer user_agent)], - default => sub { HTTP::Headers->new() }, - required => 1, + builder => 'prepare_headers', lazy => 1, ); +=head2 $self->prepare_headers($c) + +=cut + +sub prepare_headers { + my ($self) = @_; + + my $env = $self->env; + my $headers = HTTP::Headers->new(); + + for my $header (keys %{ $env }) { + next unless $header =~ /^(HTTP|CONTENT|COOKIE)/i; + (my $field = $header) =~ s/^HTTPS?_//; + $field =~ tr/_/-/; + $headers->header($field => $env->{$header}); + } + return $headers; +} + has _context => ( is => 'rw', weak_ref => 1,