From: <de...@de...> - 2008-09-28 19:50:27
|
Author: GilmarSantosJr Date: 2008-09-28 14:50:17 -0500 (Sun, 28 Sep 2008) New Revision: 17545 Trac url: http://develop.twiki.org/trac/changeset/17545 Modified: twiki/trunk/core/lib/TWiki/Engine.pm twiki/trunk/core/lib/TWiki/Response.pm Log: Item5846: minor fixes due to new tests Modified: twiki/trunk/core/lib/TWiki/Engine.pm =================================================================== --- twiki/trunk/core/lib/TWiki/Engine.pm 2008-09-28 19:49:40 UTC (rev 17544) +++ twiki/trunk/core/lib/TWiki/Engine.pm 2008-09-28 19:50:17 UTC (rev 17545) @@ -358,14 +358,15 @@ sub finalizeCookies { my ( $this, $res ) = @_; - + # SMELL: Review comment below, from CGI: # if the user indicates an expiration time, then we need # both an Expires and a Date header (so that the browser is # uses OUR clock) $res->pushHeader( 'Set-Cookie', - UNIVERSAL::isa( $_, 'CGI::Cookie' ) ? $_->as_string : $_ ) - foreach $res->cookies; + Scalar::Util::blessed $_ + && $_->isa('CGI::Cookie') ? $_->as_string : $_ ) + foreach $res->cookies; } =begin twiki Modified: twiki/trunk/core/lib/TWiki/Response.pm =================================================================== --- twiki/trunk/core/lib/TWiki/Response.pm 2008-09-28 19:49:40 UTC (rev 17544) +++ twiki/trunk/core/lib/TWiki/Response.pm 2008-09-28 19:50:17 UTC (rev 17545) @@ -44,7 +44,7 @@ package TWiki::Response; use strict; use Assert; -use CGI::Util 'rearrange'; +use CGI::Util qw(rearrange expires); =begin twiki @@ -103,10 +103,12 @@ -status => $status, -cookie => $cookie || \@cookies, -attachment => $attachName, + -charset => $charset, + -expires => $expires, -HeaderN => ValueN ) Sets response header. Resonably compatible with CGI. -Doesn't support -nph, -expires, -target and -p3p. +Doesn't support -nph, -target and -p3p. =cut @@ -116,10 +118,10 @@ # Ugly hack to avoid html escape in CGI::Util::rearrange local $CGI::Q = { escape => 0 }; - my ( $type, $status, $cookie, $charset, $attachment, @other ) = rearrange( + my ( $type, $status, $cookie, $charset, $expires, $attachment, @other ) = rearrange( [ [ 'TYPE', 'CONTENT_TYPE', 'CONTENT-TYPE' ], 'STATUS', - [ 'COOKIE', 'COOKIES' ], 'CHARSET', + [ 'COOKIE', 'COOKIES' ], 'CHARSET', 'EXPIRES', 'ATTACHMENT', ], @p @@ -168,6 +170,10 @@ ref($cookie) && ref($cookie) eq 'ARRAY' ? @$cookie : ($cookie); $this->cookies( \@cookie ); } + $this->{headers}->{Expires} = expires( $expires, 'http' ) + if ( defined $expires ); + $this->{headers}->{Date} = expires( 0, 'http' ) + if defined $expires || $cookie; $this->{headers}->{'Content-Disposition'} = "attachment; filename=\"$attachment\"" if $attachment; @@ -295,8 +301,8 @@ ---++ ObjectMethod redirect( $uri, $status, $cookies | -Location => $uri, - -Status => $status, - -Cookies => $cookies ) + -Status => $status, + -Cookies => $cookies ) Populate object with redirect response headers. @@ -315,13 +321,11 @@ ], @p ); - throw Error::Simple('TWiki::Response::redirect called without url param') - unless $url; + + return undef unless $url; + return undef if ( $status && $status !~ /^\s*3\d\d.*/ ); + my @headers = (-Location => $url); - - throw Error::Simple( - 'TWiki::Response::redirect called with invalid redirect status') - if ( $status && $status !~ /^\s*3\d\d.*/ ); push @headers, '-Status' => ( $status || '302 Found' ); push @headers, '-Cookie' => $cookies if $cookies; $this->header(@headers); |