Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Optimize Plack::Response->finalize. use HTTP::Headers->scan()

  • Loading branch information...
commit 14eabe258f2a799aa3abf0e2fe461687a0203457 1 parent 93f2cee
@kazeburo kazeburo authored
Showing with 12 additions and 16 deletions.
  1. +12 −16 lib/Plack/Response.pm
View
28 lib/Plack/Response.pm
@@ -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,
];
}
@@ -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;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.