diff options
author | Eric Wong <e@80x24.org> | 2016-05-22 03:58:00 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2016-05-22 09:05:00 +0000 |
commit | 5f1e464e0ea66f0be884f9df0a260dfafabfbee1 (patch) | |
tree | 13e886428cc2e6f75734a3e6f3f463b61c6c3522 /lib/PublicInbox/HTTP.pm | |
parent | be964491217f27aa01652becd5a173c5044772f4 (diff) | |
download | public-inbox-5f1e464e0ea66f0be884f9df0a260dfafabfbee1.tar.gz |
Unfortunately, the original design did not work because middleware can wrap the response body and make `async_pass' invisible to HTTP.pm
Diffstat (limited to 'lib/PublicInbox/HTTP.pm')
-rw-r--r-- | lib/PublicInbox/HTTP.pm | 24 |
1 files changed, 4 insertions, 20 deletions
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 4eb14481..480800bd 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -11,7 +11,7 @@ package PublicInbox::HTTP; use strict; use warnings; use base qw(Danga::Socket); -use fields qw(httpd env rbuf input_left remote_addr remote_port); +use fields qw(httpd env rbuf input_left remote_addr remote_port forward); use Fcntl qw(:seek); use Plack::HTTPParser qw(parse_http_request); # XS or pure Perl use HTTP::Status qw(status_message); @@ -219,24 +219,6 @@ sub response_write { if (ref $body eq 'ARRAY') { $write->($_) foreach @$body; $close->(); - } elsif ($body->can('async_pass')) { # HTTPD::Async - # prevent us from reading the body faster than we - # can write to the client - my $restart_read = sub { $body->watch_read(1) }; - $body->async_pass(sub { - local $/ = \8192; - my $buf = $body->getline; - if (defined $buf) { - $write->($buf); - if ($self->{write_buf_size}) { - $body->watch_read(0); - $self->write($restart_read); - } - return; # continue waiting - } - $body->close; - $close->(); - }); } else { my $pull; $pull = sub { @@ -438,7 +420,9 @@ sub event_err { $_[0]->close } sub close { my $self = shift; - $self->{env} = undef; + my $forward = $self->{forward}; + $forward->close if $forward; + $self->{forward} = $self->{env} = undef; $self->SUPER::close(@_); } |