Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

avoid parsing the response that we just generated

  • Loading branch information...
commit ef2e1242a340b8488d7d65896b95e79cb7892b19 1 parent c9e677a
Paul Driver authored

Showing 1 changed file with 22 additions and 8 deletions. Show diff stats Hide diff stats

  1. +22 8 lib/Plack/Server/POE.pm
30 lib/Plack/Server/POE.pm
@@ -9,6 +9,7 @@ use Plack::Util;
9 9 use POE qw(
10 10 Component::Server::TCP
11 11 Filter::HTTP::Parser
  12 + Filter::Stream
12 13 );
13 14
14 15 sub new {
@@ -24,10 +25,11 @@ sub run {
24 25 my ($self, $app) = @_;
25 26 my $filter = POE::Filter::HTTP::Parser->new( type => 'server' );
26 27 POE::Component::Server::TCP->new(
27   - Port => $self->{port},
28   - Address => $self->{host},
29   - ClientFilter => $filter,
30   - ClientInput => sub {
  28 + Port => $self->{port},
  29 + Address => $self->{host},
  30 + ClientInputFilter => $filter,
  31 + ClientOutputFilter => 'POE::Filter::Stream',
  32 + ClientInput => sub {
31 33 my ($kernel, $heap, $req) = @_[KERNEL, HEAP, ARG0];
32 34 my $client = $heap->{client};
33 35 my $env = req_to_psgi($req,
@@ -36,10 +38,22 @@ sub run {
36 38 'psgi.nonblocking' => Plack::Util::TRUE,
37 39 'psgi.runonce' => Plack::Util::FALSE,
38 40 );
39   - my $res = res_from_psgi(Plack::Util::run_app $app, $env);
40   - # fix some brokenness
41   - $res->message(status_message($res->code));
42   - $client->put($res);
  41 +
  42 + my ($code, $headers, $body_iter) =
  43 + @{ Plack::Util::run_app($app, $env) };
  44 +
  45 + my $protocol = $req->protocol || 'HTTP/0.9';
  46 + my $message = status_message($code);
  47 + $client->put("$protocol $code $message\r\n");
  48 +
  49 + while (@$headers) {
  50 + my $k = shift(@$headers);
  51 + my $v = shift(@$headers);
  52 + $client->put("$k: $v\r\n");
  53 + }
  54 + $client->put("\r\n");
  55 + Plack::Util::foreach($body_iter, sub { $client->put($_[0]) });
  56 +
43 57 $poe_kernel->yield('shutdown');
44 58 },
45 59 );

0 comments on commit ef2e124

Please sign in to comment.
Something went wrong with that request. Please try again.