Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
small optimizations
  • Loading branch information
kraih committed May 12, 2013
1 parent fb4a3eb commit d5452f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
27 changes: 10 additions & 17 deletions lib/Mojo/Message.pm
Expand Up @@ -49,11 +49,8 @@ sub body_params {

# "multipart/formdata"
elsif ($type =~ m!multipart/form-data!i) {
my $formdata = $self->_parse_formdata;
for my $data (@$formdata) {
my ($name, $filename, $value) = @$data;
next if defined $filename;
$params->append($name, $value);
for my $data (@{$self->_parse_formdata}) {
$params->append($data->[0], $data->[2]) unless defined $data->[1];
}
}

Expand Down Expand Up @@ -212,19 +209,17 @@ sub uploads {
my $self = shift;

my @uploads;
my $formdata = $self->_parse_formdata;
for my $data (@$formdata) {
my ($name, $filename, $part) = @$data;
for my $data (@{$self->_parse_formdata}) {

# Just a form value
next unless defined $filename;
next unless defined $data->[1];

# Uploaded file
my $upload = Mojo::Upload->new(
name => $name,
asset => $part->asset,
filename => $filename,
headers => $part->headers
name => $data->[0],
filename => $data->[1],
asset => $data->[2]->asset,
headers => $data->[2]->headers
);
push @uploads, $upload;
}
Expand Down Expand Up @@ -275,8 +270,7 @@ sub _parse_formdata {
my $charset = $content->charset || $self->default_charset;

# Check all parts for form data
my @parts;
push @parts, $content;
my @parts = ($content);
while (my $part = shift @parts) {

# Nested multipart content
Expand All @@ -286,8 +280,7 @@ sub _parse_formdata {
}

# Extract information from Content-Disposition header
my $disposition = $part->headers->content_disposition;
next unless $disposition;
next unless my $disposition = $part->headers->content_disposition;
my ($name) = $disposition =~ /[; ]name="?([^";]+)"?/;
my ($filename) = $disposition =~ /[; ]filename="?([^"]*)"?/;
if ($charset) {
Expand Down
1 change: 0 additions & 1 deletion t/mojo/request.t
Expand Up @@ -222,7 +222,6 @@ is $req->content->leftovers, "GET / HTTP/1.1\x0d\x0a\x0d\x0a",
'second request in leftovers';

# Parse HTTP 1.1 start line, no headers and body with leading CRLFs
# (SHOULD be ignored, RFC 2616, Section 4.1)
$req = Mojo::Message::Request->new;
$req->parse("\x0d\x0a GET / HTTP/1.1\x0d\x0a\x0d\x0a");
ok $req->is_finished, 'request is finished';
Expand Down

0 comments on commit d5452f4

Please sign in to comment.