about summary refs log tree commit homepage
path: root/lib/PublicInbox/HTTP.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-04-29 03:32:20 +0000
committerEric Wong <e@80x24.org>2016-04-29 20:03:17 +0000
commitf947a355417328a96b1bbe43223cbae79fc10345 (patch)
tree416770c545d78c6bbdbd10e0ec17db3a60a3f833 /lib/PublicInbox/HTTP.pm
parent0b0d9b7f6237593c69dc38ec64566343fd20191c (diff)
downloadpublic-inbox-f947a355417328a96b1bbe43223cbae79fc10345.tar.gz
We need to abort connections properly if a response is prematurely
truncated.  This includes problems with serving static files, since
a clumsy admin or broken FS could return truncated responses and
inadvertently leave a client waiting (since the client saw
"Content-Length" in the header and expected a certain length).
Diffstat (limited to 'lib/PublicInbox/HTTP.pm')
-rw-r--r--lib/PublicInbox/HTTP.pm9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm
index c7fb954e..973da341 100644
--- a/lib/PublicInbox/HTTP.pm
+++ b/lib/PublicInbox/HTTP.pm
@@ -135,6 +135,9 @@ sub app_dispatch ($) {
         sysseek($env->{'psgi.input'}, 0, SEEK_SET) or
                         die "BUG: psgi.input seek failed: $!";
 
+        # note: NOT $self->{sock}, we want our close (+ Danga::Socket::close),
+        # to do proper cleanup:
+        $env->{'psgix.io'} = $self; # only for ->close
         my $res = Plack::Util::run_app($self->{httpd}->{app}, $env);
         eval {
                 if (ref($res) eq 'CODE') {
@@ -371,6 +374,12 @@ sub quit {
 sub event_hup { $_[0]->close }
 sub event_err { $_[0]->close }
 
+sub close {
+        my $self = shift;
+        $self->{env} = undef;
+        $self->SUPER::close(@_);
+}
+
 sub write ($$) : method {
         my PublicInbox::HTTP $self = $_[0];
         return 1 if (defined($_[1]) && ref($_[1]) eq '' && $_[1] eq '');