From: John Napiorkowski Date: Sat, 10 Jan 2015 23:30:29 +0000 (-0600) Subject: fixed another regression X-Git-Tag: 5.90083~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=67fd25bc03bc87a19db237a13fcb1cd157252101;hp=c7f851424be516dd34be1e6825bda8e46201507d fixed another regression --- diff --git a/Changes b/Changes index f921176..a6d45f7 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,9 @@ # This file documents the revision history for Perl extension Catalyst. +5.90082 - 2014-01-10 + - Fixed a regression created in $response->from_psgi_response and test case + to prevent it happening again. + 5.90081 - 2014-01-10 - created class attribute 'finalized_default_middleware' which determines if the default middleware has been added to the stack yet or not. This diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index e32c735..d6717cb 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -129,7 +129,7 @@ __PACKAGE__->stats_class('Catalyst::Stats'); __PACKAGE__->_encode_check(Encode::FB_CROAK | Encode::LEAVE_SRC); # Remember to update this in Catalyst::Runtime as well! -our $VERSION = '5.90081'; +our $VERSION = '5.90082'; $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases sub import { diff --git a/lib/Catalyst/Response.pm b/lib/Catalyst/Response.pm index 6143f25..74d59fe 100644 --- a/lib/Catalyst/Response.pm +++ b/lib/Catalyst/Response.pm @@ -148,7 +148,10 @@ sub from_psgi_response { my ($status, $headers, $body) = @$psgi_res; $self->status($status); $self->headers(HTTP::Headers->new(@$headers)); - $self->body(join('', @$body)); + # Can be arrayref or filehandle... + if(defined $body) { # probably paranoia + ref $body eq 'ARRAY' ? $self->body(join('', @$body)) : $self->body($body); + } } elsif(ref $psgi_res eq 'CODE') { $psgi_res->(sub { my $response = shift; @@ -156,7 +159,8 @@ sub from_psgi_response { $self->status($status); $self->headers(HTTP::Headers->new(@$headers)); if(defined $maybe_body) { - $self->body(join('', @$maybe_body)); + # Can be arrayref or filehandle... + ref $maybe_body eq 'ARRAY' ? $self->body(join('', @$maybe_body)) : $self->body($maybe_body); } else { return $self->write_fh; } diff --git a/lib/Catalyst/Runtime.pm b/lib/Catalyst/Runtime.pm index 466d54a..5b76616 100644 --- a/lib/Catalyst/Runtime.pm +++ b/lib/Catalyst/Runtime.pm @@ -7,7 +7,7 @@ BEGIN { require 5.008003; } # Remember to update this in Catalyst as well! -our $VERSION = '5.90081'; +our $VERSION = '5.90082'; $VERSION = eval $VERSION if $VERSION =~ /_/; # numify for warning-free dev releases =head1 NAME diff --git a/t/psgi_utils.t b/t/psgi_utils.t index 9c05559..eb69e9d 100644 --- a/t/psgi_utils.t +++ b/t/psgi_utils.t @@ -43,6 +43,18 @@ my $psgi_app = sub { $psgi_app->($env)); } + sub filehandle :Local { + my ($self, $c, $arg) = @_; + my $path = File::Spec->catfile('t', 'utf8.txt'); + open(my $fh, '<', $path) || die "trouble: $!"; + $c->res->from_psgi_response([200, ['Content-Type'=>'text/html'], $fh]); + } + + sub direct :Local { + my ($self, $c, $arg) = @_; + $c->res->from_psgi_response([200, ['Content-Type'=>'text/html'], ["hello","world"]]); + } + package MyApp::Controller::User; $INC{'MyApp/Controller/User.pm'} = __FILE__; @@ -383,4 +395,16 @@ use Catalyst::Test 'MyApp'; is_deeply $c->req->args, [111]; } +{ + use utf8; + use Encode; + my ($res, $c) = ctx_request('/docs/filehandle'); + is Encode::decode_utf8($res->content), "

This is stream_body_fh action ♥

\n"; +} + +{ + my ($res, $c) = ctx_request('/docs/direct'); + is $res->content, "helloworld"; +} + done_testing();