Merge branch 'bokutin-bugs/from_psgi_response'
John Napiorkowski [Wed, 16 Jan 2019 14:37:15 +0000 (08:37 -0600)]
lib/Catalyst/Response.pm
t/psgi_utils.t

index 2399ae5..b0f04a3 100644 (file)
@@ -196,6 +196,8 @@ sub from_psgi_response {
         die "You can't set a Catalyst response from that, expect a valid PSGI response";
     }
 
+    return unless $self->_context->has_encoding;
+
     # Encoding compatibilty.   If the response set a charset, well... we need
     # to assume its properly encoded and NOT encode for this response.  Otherwise
     # We risk double encoding.
index 6508886..923defb 100644 (file)
@@ -55,6 +55,28 @@ my $psgi_app = sub {
     $c->res->from_psgi_response([200, ['Content-Type'=>'text/html'], ["hello","world"]]);
   }
 
+  sub streaming_body :Local {
+    my ($self, $c) = @_;
+    my $psgi_app = sub {
+        my $respond = shift;
+        my $writer = $respond->([200,["Content-Type" => "text/plain"]]);
+        $writer->write("body");
+        $writer->close;
+    };
+    $c->res->from_psgi_response($psgi_app);
+  }
+  sub streaming_body_with_charset :Local {
+    my ($self, $c) = @_;
+    my $psgi_app = sub {
+        my $respond = shift;
+        my $writer = $respond->([200,["Content-Type" => "text/plain; charset=utf-8"]]);
+        $writer->write("body");
+        $writer->close;
+    };
+    $c->clear_encoding;
+    $c->res->from_psgi_response($psgi_app);
+  }
+
   package MyApp::Controller::User;
   $INC{'MyApp/Controller/User.pm'} = __FILE__;
 
@@ -407,4 +429,13 @@ use Catalyst::Test 'MyApp';
   is $res->content, "helloworld";
 }
 
+{
+  my ($res, $c) = ctx_request('/docs/streaming_body');
+  is $res->content, "body";
+}
+{
+  my ($res, $c) = ctx_request('/docs/streaming_body_with_charset');
+  is $res->content, "body";
+}
+
 done_testing();