- if ($code == 403) {
- # smart cloning disabled, serve dumbly
- # in $end since we never undef $res in here
- } else { # write response header:
- $fh = $res->([ $code, \@h ]);
- $res = undef;
- $fh->write($buf);
+ $res->($r);
+ } elsif ($async) {
+ $fh = $res->($r);
+ $async->async_pass($env->{'psgix.io'}, $fh, \$buf);
+ } else { # for synchronous PSGI servers
+ require PublicInbox::GetlineBody;
+ $r->[2] = PublicInbox::GetlineBody->new($rpipe, $end,
+ $buf);
+ $res->($r);
+ }
+ };
+ sub {
+ ($res) = @_;
+
+ # hopefully this doesn't break any middlewares,
+ # holding the input here is a waste of FDs and memory
+ $env->{'psgi.input'} = undef;
+
+ $qsp->start($limiter, sub { # may run later, much later...
+ ($rpipe) = @_;
+ $in = undef;
+ if ($async) {
+ $async = $async->($rpipe, $cb, $end);
+ } else { # generic PSGI
+ $cb->() while $rd_hdr;