Do not destroy callback interface (clkao)
Tatsuhiko Miyagawa [Sat, 19 Dec 2009 18:08:29 +0000 (10:08 -0800)]
lib/Plack/Middleware/Session.pm
t/011_streaming.t [new file with mode: 0644]

index dab15cb..b378243 100644 (file)
@@ -55,7 +55,9 @@ sub call {
     $self->response_cb($res, sub {
         my $res = Plack::Response->new(@{$_[0]});
         $env->{'plack.session'}->finalize( $res );
-        @{$_[0]} = @{$res->finalize};
+        $res = $res->finalize;
+        $_[0]->[0] = $res->[0];
+        $_[0]->[1] = $res->[1];
     });
 }
 
diff --git a/t/011_streaming.t b/t/011_streaming.t
new file mode 100644 (file)
index 0000000..9c85592
--- /dev/null
@@ -0,0 +1,30 @@
+use strict;
+use Test::More;
+use Test::Requires qw(Plack::Server::AnyEvent);
+use Plack::Test;
+use Plack::Middleware::Session;
+use HTTP::Request::Common;
+
+$Plack::Test::Impl = 'Server';
+$ENV{PLACK_SERVER} = 'AnyEvent';
+
+my $app = sub {
+    return sub {
+        my $respond = shift;
+        my $w = $respond->([ 200, [ 'Content-Type' => 'text/html' ] ]);
+        $w->write("Hello");
+        $w->close;
+    };
+};
+
+$app = Plack::Middleware::Session->wrap($app);
+
+test_psgi $app, sub {
+    my $cb = shift;
+
+    my $res = $cb->(GET "/");
+    is $res->content, "Hello";
+    like $res->header('Set-Cookie'), qr/plack_session/;
+};
+
+done_testing;