- if (my $middle = $self->{cb}) {
- $middle = $middle->($nr, $self->{ctx}) and return $middle;
- }
+sub html_oneshot ($$;@) {
+ my ($ctx, $code) = @_[0, 1];
+ my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8',
+ 'Content-Length' => undef ];
+ bless $ctx, __PACKAGE__;
+ $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
+ my @top;
+ $ctx->{base_url} // do {
+ @top = html_top($ctx);
+ $ctx->{base_url} = base_url($ctx);
+ };
+ my $bdy = $ctx->zflush(@top, @_[2..$#_], _html_end($ctx));
+ $res_hdr->[3] = length($bdy);
+ [ $code, $res_hdr, [ $bdy ] ]
+}
+
+sub async_next ($) {
+ my ($http) = @_; # PublicInbox::HTTP
+ my $ctx = $http->{forward} or return;
+ eval {
+ if (my $smsg = $ctx->{smsg} = $ctx->{cb}->($ctx)) {
+ $ctx->smsg_blob($smsg);
+ } else {
+ $ctx->write(_html_end($ctx));
+ $ctx->close; # GzipFilter->close
+ }
+ };
+ warn "E: $@" if $@;
+}