$c->finalize_error;
}
- if ( !$c->response->body_length && $c->response->status !~ /^(1|3)\d\d$/ ) {
+ if ( !$c->response->body && $c->response->status !~ /^(1|3)\d\d$/ ) {
$c->finalize_error;
}
- if ( $c->response->body_length && !$c->response->content_length ) {
- $c->response->content_length( $c->response->body_length );
+ if ( $c->response->body && !$c->response->content_length ) {
+ use bytes; # play safe with a utf8 aware perl
+ $c->response->content_length( length $c->response->body );
}
my $status = $c->finalize_headers;
request => Catalyst::Request->new(
{
arguments => [],
- body => undef,
cookies => {},
headers => HTTP::Headers->new,
parameters => {},
}
),
response => Catalyst::Response->new(
- {
- body => undef,
- cookies => {},
- headers => HTTP::Headers->new,
- status => 200
- }
+ { cookies => {}, headers => HTTP::Headers->new, status => 200 }
),
stash => {},
state => 0
}
$c->prepare_request($engine);
- $c->prepare_connection;
+ $c->prepare_path;
$c->prepare_headers;
$c->prepare_cookies;
- $c->prepare_path;
+ $c->prepare_connection;
$c->prepare_action;
my $method = $c->req->method || '';
sub referer { shift->headers->referer(@_) }
sub user_agent { shift->headers->user_agent(@_) }
+sub _assign_values {
+ my ( $self, $map, $values ) = @_;
+
+ while ( my ( $name, $value ) = splice( @{$values}, 0, 2 ) ) {
+
+ if ( exists $map->{$name} ) {
+ for ( $map->{$name} ) {
+ $_ = [$_] unless ref($_) eq "ARRAY";
+ push( @$_, $value );
+ }
+ }
+ else {
+ $map->{$name} = $value;
+ }
+ }
+}
+
=head1 NAME
Catalyst::Request - Catalyst Request Class
$req->arguments;
$req->base;
$req->body;
- $req->body_length;
- $req->body_ref;
$req->content_encoding;
$req->content_length;
$req->content_type;
print $c->request->body
-=item $req->body_length
-
-Returns the length of body in bytes.
-
- print $c->request->body_length
-
-=cut
-
-sub body_length {
- my $self = shift;
-
- use bytes;
-
- return 0 unless $self->body;
- return length($self->body);
-}
-
-=item $req->body_ref
-
-Returns a reference to body.
-
-=cut
-
-sub body_ref {
- my $self = shift;
- return \$self->{body};
-}
-
=item $req->content_encoding
Shortcut to $req->headers->content_encoding
return keys %{ $self->parameters };
}
- if ( @_ == 1 and ref( $_[0] ) eq 'ARRAY' ) {
-
- while ( my ( $field, $value ) = splice( @{ $_[0] }, 0, 2 ) ) {
+ my $param = shift;
- if ( exists $self->parameters->{$field} ) {
- for ( $self->parameters->{$field} ) {
- $_ = [$_] unless ref($_) eq "ARRAY";
- push( @$_, $value );
- }
- }
- else {
- $self->parameters->{$field} = $value;
- }
- }
+ unless ( exists $self->parameters->{$param} ) {
+ return wantarray ? () : undef;
}
-
- if ( @_ == 1 ) {
-
- my $param = shift;
-
- unless ( exists $self->parameters->{$param} ) {
- return wantarray ? () : undef;
- }
- if ( ref $self->parameters->{$param} eq 'ARRAY' ) {
- return (wantarray)
- ? @{ $self->parameters->{$param} }
- : $self->parameters->{$param}->[0];
- }
- else {
- return (wantarray)
- ? ( $self->parameters->{$param} )
- : $self->parameters->{$param};
- }
- }
+ if ( ref $self->parameters->{$param} eq 'ARRAY' ) {
+ return (wantarray)
+ ? @{ $self->parameters->{$param} }
+ : $self->parameters->{$param}->[0];
+ }
+ else {
+ return (wantarray)
+ ? ( $self->parameters->{$param} )
+ : $self->parameters->{$param};
+ }
}
=item $req->params
$upload = $c->request->upload('field');
@uploads = $c->request->upload('field');
@fields = $c->request->upload;
-
+
for my $upload ( $c->request->upload('field') ) {
print $upload->filename;
}
return keys %{ $self->uploads };
}
- if ( @_ == 1 and ref( $_[0] ) eq 'ARRAY' ) {
-
- while ( my ( $field, $upload ) = splice( @{ $_[0] }, 0, 2 ) ) {
+ my $upload = shift;
- if ( exists $self->uploads->{$field} ) {
- for ( $self->uploads->{$field} ) {
- $_ = [$_] unless ref($_) eq "ARRAY";
- push( @$_, $upload );
- }
- }
- else {
- $self->uploads->{$field} = $upload;
- }
- }
+ unless ( exists $self->uploads->{$upload} ) {
+ return wantarray ? () : undef;
}
- if ( @_ == 1 ) {
-
- my $upload = shift;
-
- unless ( exists $self->uploads->{$upload} ) {
- return wantarray ? () : undef;
- }
-
- if ( ref $self->uploads->{$upload} eq 'ARRAY' ) {
- return (wantarray)
- ? @{ $self->uploads->{$upload} }
- : $self->uploads->{$upload}->[0];
- }
- else {
- return (wantarray)
- ? ( $self->uploads->{$upload} )
- : $self->uploads->{$upload};
- }
+ if ( ref $self->uploads->{$upload} eq 'ARRAY' ) {
+ return (wantarray)
+ ? @{ $self->uploads->{$upload} }
+ : $self->uploads->{$upload}->[0];
+ }
+ else {
+ return (wantarray)
+ ? ( $self->uploads->{$upload} )
+ : $self->uploads->{$upload};
}
}
=item $req->uploads
-Returns a reference to a hash containing uploads. Values can be either a
+Returns a reference to a hash containing uploads. Values can be either a
hashref or a arrayref containing C<Catalyst::Request::Upload> objects.
my $upload = $c->request->uploads->{field};