]> Sergey Matveev's repositories - public-inbox.git/commitdiff
wwwstatic: getline: die on missing psgix.io
authorEric Wong <e@80x24.org>
Tue, 31 Dec 2019 10:30:09 +0000 (10:30 +0000)
committerEric Wong <e@80x24.org>
Wed, 1 Jan 2020 07:50:23 +0000 (07:50 +0000)
"psgix." extensions aren't guaranteed, so make we should
try and support some theoretical generic PSGI servers
without "psgix.io" on errors by die-ing.

While we're at it, make the error handling path more obvious by
sharing more code between the EOF and errno ($!) cases.

lib/PublicInbox/WwwStatic.pm

index 76e50c789b7336a653e99de9e46afbe67dee9203..58db58b4e76755aac5ae8ad4f5d944865858d401 100644 (file)
@@ -77,25 +77,23 @@ sub response {
 # called by PSGI servers:
 sub getline {
        my ($self) = @_;
-       my $len = $self->{len};
-       return if $len == 0;
+       my $len = $self->{len} or return; # undef, tells server we're done
        my $n = delete($self->{initial_rd}) // 8192;
        $n = $len if $len < $n;
        my $r = sysread($self->{in}, my $buf, $n);
-       if (!defined $r) {
-               $self->{env}->{'psgi.errors'}->print(
-                       "$self->{path} read error: $!\n");
-       } elsif ($r > 0) { # success!
+       if (defined $r && $r > 0) { # success!
                $self->{len} = $len - $r;
                return $buf;
-       } else {
-               $self->{env}->{'psgi.errors'}->print(
-                       "$self->{path} EOF with $len bytes left\n");
        }
+       my $m = defined $r ? "EOF with $len bytes left" : "read error: $!";
+       my $env = $self->{env};
+       $env->{'psgi.errors'}->print("$self->{path} $m\n");
 
        # drop the client on error
-       if (my $io = $self->{env}->{'psgix.io'}) {
-               $io->close; # this is PublicInbox::DS::close
+       if (my $io = $env->{'psgix.io'}) {
+               $io->close; # this is likely PublicInbox::DS::close
+       } else { # for some PSGI servers w/o psgix.io
+               die "dropping client socket\n";
        }
        undef;
 }