X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FRequest.pm;h=442f88825b9007f6c46a63506c9a4a39ce7e86f2;hb=767480fd8b4151e350831a52dbc9c6265bf84485;hp=cf695ffeb9cf4c175ed6b1b84fb1fa8c4eb4110d;hpb=2f498a7ee1e99938c3684604336d99488c9d6499;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/Request.pm b/lib/Catalyst/Request.pm index cf695ff..442f888 100644 --- a/lib/Catalyst/Request.pm +++ b/lib/Catalyst/Request.pm @@ -25,10 +25,26 @@ has _read_length => ( is => 'ro', lazy => 1, ); -has action => (is => 'rw'); +has action => (is => 'rw'); # XXX Deprecated - warn? 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,15 +58,33 @@ 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, ); -has _context => ( - is => 'rw', - weak_ref => 1, - clearer => '_clear_context', +=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 _log => ( + is => 'ro', + weak_ref => 1, + required => 1, ); # Amount of data to read from input on each pass @@ -231,7 +265,7 @@ around parameters => sub { my ($orig, $self, $params) = @_; if ($params) { if ( !ref $params ) { - $self->_context->log->warn( + $self->_log->warn( "Attempt to retrieve '$params' with req->params(), " . "you probably meant to call req->param('$params')" ); @@ -297,8 +331,7 @@ Catalyst::Request - provides information about the current client request =head1 SYNOPSIS $req = $c->request; - $req->action; - $req->address; + $req->address eq "127.0.0.1"; $req->arguments; $req->args; $req->base; @@ -342,14 +375,6 @@ thus hiding the details of the particular engine implementation. =head1 METHODS -=head2 $req->action - -[DEPRECATED] Returns the name of the requested action. - - -Use C<< $c->action >> instead (which returns a -L object). - =head2 $req->address Returns the IP address of the client.