Skip to content

Commit

Permalink
Merge pull request #433 from kazeburo/master
Browse files Browse the repository at this point in the history
Optimize Plack::Response->finalize
  • Loading branch information
miyagawa committed Oct 22, 2013
2 parents 8ec3140 + 14eabe2 commit f168ddc
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions lib/Plack/Response.pm
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,20 @@ sub finalize {
my $self = shift;
Carp::croak "missing status" unless $self->status();

my $headers = $self->headers->clone;
$self->_finalize_cookies($headers);
my $headers = $self->headers;
my @headers;
$headers->scan(sub{
my ($k,$v) = @_;
$v =~ s/\015\012[\040|\011]+/chr(32)/ge; # replace LWS with a single SP
$v =~ s/\015|\012//g; # remove CR and LF since the char is invalid here
push @headers, $k, $v;
});

$self->_finalize_cookies(\@headers);

return [
$self->status,
+[
map {
my $k = $_;
map {
my $v = $_;
$v =~ s/\015\012[\040|\011]+/chr(32)/ge; # replace LWS with a single SP
$v =~ s/\015|\012//g; # remove CR and LF since the char is invalid here

( $k => $v )
} $headers->header($_);

} $headers->header_field_names
],
\@headers,
$self->_body,
];
}
Expand All @@ -129,7 +125,7 @@ sub _finalize_cookies {

while (my($name, $val) = each %{$self->cookies}) {
my $cookie = $self->_bake_cookie($name, $val);
$headers->push_header('Set-Cookie' => $cookie);
push @$headers, 'Set-Cookie' => $cookie;
}
}

Expand Down

0 comments on commit f168ddc

Please sign in to comment.