X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FHTTP.pm;h=e19c592c99612ae29960676e5112166d5f5642eb;hb=5422a844b7384c32b3532d128e15e0b50d24435b;hp=0454f607777e7b972956fee5f5002159beac5fc4;hpb=656bc41ecb1a77208adaeee6c68faed3e8328695;p=public-inbox.git diff --git a/lib/PublicInbox/HTTP.pm b/lib/PublicInbox/HTTP.pm index 0454f607..e19c592c 100644 --- a/lib/PublicInbox/HTTP.pm +++ b/lib/PublicInbox/HTTP.pm @@ -4,7 +4,7 @@ # Generic PSGI server for convenience. It aims to provide # a consistent experience for public-inbox admins so they don't have # to learn different ways to admin both NNTP and HTTP components. -# There's nothing public-inbox-specific, here. +# There's nothing which depends on public-inbox, here. # Each instance of this class represents a HTTP client socket package PublicInbox::HTTP; @@ -25,7 +25,7 @@ use constant { CHUNK_MAX_HDR => 256, }; -# FIXME: duplicated code with NNTP.pm +# FIXME: duplicated code with NNTP.pm, layering violation my $WEAKEN = {}; # string(inbox) -> inbox my $weakt; sub weaken_task () { @@ -223,7 +223,10 @@ sub chunked_wcb ($) { return if $_[0] eq ''; more($self, sprintf("%x\r\n", bytes::length($_[0]))); more($self, $_[0]); - $self->write("\r\n"); + + # use $self->write("\n\n") if you care about real-time + # streaming responses, public-inbox WWW does not. + more($self, "\r\n"); } } @@ -249,6 +252,8 @@ sub response_done ($$) { $self->{env} = undef; $self->write("0\r\n\r\n") if $alive == 2; $self->write(sub { $alive ? next_request($self) : $self->close }); + + # FIXME: layering violation if (my $obj = $env->{'pi-httpd.inbox'}) { # grace period for reaping resources $WEAKEN->{"$obj"} = $obj; @@ -263,13 +268,17 @@ sub getline_response { my $pull = $self->{pull} = sub { local $/ = \8192; my $forward = $self->{forward}; + # limit our own running time for fairness with other + # clients and to avoid buffering too much: while ($forward && defined(my $buf = $forward->getline)) { $write->($buf); last if $self->{closed}; if ($self->{write_buf_size}) { $self->write($self->{pull}); - return; + } else { + PublicInbox::EvCleanup::asap($self->{pull}); } + return; } $self->{forward} = $self->{pull} = undef; $forward->close if $forward; # avoid recursion