Permalink
Browse files

use clone

  • Loading branch information...
1 parent 2b5bf24 commit bd9588987e26e8cf5c4dde0c56a2082baaefdd46 Ryo Anazawa committed Jun 8, 2013
Showing with 18 additions and 12 deletions.
  1. +12 −6 lib/CGI/Header/Adapter.pm
  2. +5 −5 lib/CGI/Header/Apache2.pm
  3. +1 −1 t/30_adapter.t
View
@@ -60,16 +60,18 @@ sub process_newline {
}
sub as_arrayref {
- my $self = shift;
- my $query = $self->query;
- my %header = %{ $self->header };
+ my $self = shift;
+ my $query = $self->query;
if ( $self->handler eq 'redirect' ) {
- $header{location} = $query->self_url if !$header{location};
- $header{status} = '302 Found' if !defined $header{status};
- $header{type} = q{} if !exists $header{type};
+ $self = $self->clone;
+ $self->location( $query->self_url ) if !$self->location;
+ $self->status( '302 Found' ) if !defined $self->status;
+ $self->type( q{} ) if !$self->_has_type;
}
+ my %header = %{ $self->header };
+
my ( $attachment, $charset, $cookies, $expires, $nph, $p3p, $status, $target, $type )
= delete @header{qw/attachment charset cookies expires nph p3p status target type/};
@@ -121,6 +123,10 @@ sub _date {
CGI::Util::expires( $expires, 'http' );
}
+sub _has_type {
+ exists $_[0]->header->{type};
+}
+
1;
__END__
View
@@ -15,7 +15,7 @@ sub finalize {
my $headers = $self->as_arrayref;
my $request_rec = $self->request_rec;
- my $status = $self->status || ( $self->handler eq 'redirect' ? '302' : '200' );
+ my $status = {@$headers}->{'Status'} || '200';
$status =~ s/\D*$//;
my $headers_out = $status >= 200 && $status < 300 ? 'headers_out' : 'err_headers_out';
@@ -27,12 +27,12 @@ sub finalize {
my $field = $headers->[$i];
my $value = $self->process_newline( $headers->[$i+1] );
- if ( $field eq 'Content-legnth' ) {
- $request_rec->set_content_length( $value );
- }
- elsif ( $field eq 'Content-Type' ) {
+ if ( $field eq 'Content-Type' ) {
$request_rec->content_type( $value );
}
+ elsif ( $field eq 'Content-length' ) {
+ $request_rec->set_content_length( $value );
+ }
elsif ( $field eq 'Status' ) {
$request_rec->status_line( $value );
}
View
@@ -4,7 +4,7 @@ use Test::MockTime qw/set_fixed_time/;
use CGI;
use CGI::Cookie;
use CGI::Header::Adapter;
-use Test::More tests => 3;
+use Test::More tests => 4;
use Test::Exception;
set_fixed_time( 1341637509 );

0 comments on commit bd95889

Please sign in to comment.