- # middlewares such as Deflater may write empty strings
- my $write = sub { $self->write($_[0]) if $_[0] ne '' };
- my $close = sub {
- if ($alive) {
- $self->event_write; # watch for readability if done
+ # use $self->write(\"\n\n") if you care about real-time
+ # streaming responses, public-inbox WWW does not.
+ msg_more($self, "\r\n");
+}
+
+sub identity_write ($$) {
+ my $self = $_[0];
+ $self->write(\($_[1])) if $_[1] ne '';
+}
+
+sub next_request ($) {
+ my ($self) = @_;
+ if ($self->{rbuf}) {
+ # avoid recursion for pipelined requests
+ PublicInbox::DS::requeue(\&process_pipelineq) if !@$pipelineq;
+ push @$pipelineq, $self;
+ } else { # wait for next request
+ $self->requeue;
+ }
+}
+
+sub response_done {
+ my ($self, $alive) = @_;
+ delete $self->{env}; # we're no longer busy
+ $self->write(\"0\r\n\r\n") if $alive == 2;
+ $self->write($alive ? \&next_request : \&close);
+}
+
+sub getline_pull {
+ my ($self) = @_;
+ my $forward = $self->{forward};
+
+ # limit our own running time for fairness with other
+ # clients and to avoid buffering too much:
+ my $buf = eval {
+ local $/ = \8192;
+ $forward->getline;
+ } if $forward;
+
+ if (defined $buf) {
+ # may close in PublicInbox::DS::write
+ if ($self->{alive} == 2) {
+ chunked_write($self, $buf);