- if (my $gzf = gzf_maybe($h, $ctx->{env})) {
- $gzf->zmore(_html_top($self));
- $gzf->zmore($$sref) if $sref;
- $x[0] = $gzf->zflush(_html_end($self));
- $h->[3] = length($x[0]);
- } else {
- @x = (_html_top($self), $sref ? $$sref : (), _html_end($self));
- $h->[3] += bytes::length($_) for @x;
- }
- [ $code, $h, \@x ]
+ bless $ctx, __PACKAGE__;
+ $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
+ $ctx->{base_url} //= do {
+ $ctx->zmore(html_top($ctx));
+ base_url($ctx);
+ };
+ $ctx->zmore($$sref) if $sref;
+ my $bdy = $ctx->zflush(_html_end($ctx));
+ $res_hdr->[3] = bytes::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->{http_out}->write(
+ $ctx->translate(_html_end($ctx)));
+ $ctx->close; # GzipFilter->close
+ }
+ };
+ warn "E: $@" if $@;
+}
+
+sub aresponse {
+ my ($ctx, $code, $cb) = @_;
+ my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
+ init($ctx, $cb);
+ $ctx->psgi_response($code, $res_hdr, \&async_next, \&async_eml);