Permalink
Browse files

avoid parsing the response that we just generated

  • Loading branch information...
1 parent c9e677a commit ef2e1242a340b8488d7d65896b95e79cb7892b19 @frodwith committed Oct 15, 2009
Showing with 22 additions and 8 deletions.
  1. +22 −8 lib/Plack/Server/POE.pm
View
30 lib/Plack/Server/POE.pm
@@ -9,6 +9,7 @@ use Plack::Util;
use POE qw(
Component::Server::TCP
Filter::HTTP::Parser
+ Filter::Stream
);
sub new {
@@ -24,10 +25,11 @@ sub run {
my ($self, $app) = @_;
my $filter = POE::Filter::HTTP::Parser->new( type => 'server' );
POE::Component::Server::TCP->new(
- Port => $self->{port},
- Address => $self->{host},
- ClientFilter => $filter,
- ClientInput => sub {
+ Port => $self->{port},
+ Address => $self->{host},
+ ClientInputFilter => $filter,
+ ClientOutputFilter => 'POE::Filter::Stream',
+ ClientInput => sub {
my ($kernel, $heap, $req) = @_[KERNEL, HEAP, ARG0];
my $client = $heap->{client};
my $env = req_to_psgi($req,
@@ -36,10 +38,22 @@ sub run {
'psgi.nonblocking' => Plack::Util::TRUE,
'psgi.runonce' => Plack::Util::FALSE,
);
- my $res = res_from_psgi(Plack::Util::run_app $app, $env);
- # fix some brokenness
- $res->message(status_message($res->code));
- $client->put($res);
+
+ my ($code, $headers, $body_iter) =
+ @{ Plack::Util::run_app($app, $env) };
+
+ my $protocol = $req->protocol || 'HTTP/0.9';
+ my $message = status_message($code);
+ $client->put("$protocol $code $message\r\n");
+
+ while (@$headers) {
+ my $k = shift(@$headers);
+ my $v = shift(@$headers);
+ $client->put("$k: $v\r\n");
+ }
+ $client->put("\r\n");
+ Plack::Util::foreach($body_iter, sub { $client->put($_[0]) });
+
$poe_kernel->yield('shutdown');
},
);

0 comments on commit ef2e124

Please sign in to comment.