- my $self = bless {
- ctx => $ctx,
- base_url => base_url($ctx),
- }, __PACKAGE__;
- my @x;
- my $h = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
- if (my $gz = gzip_maybe($h, $ctx->{env})) {
- my $err = $gz->deflate(_html_top($self), $x[0]);
- die "gzip->deflate: $err" if $err != Z_OK;
- if ($sref) {
- $err = $gz->deflate($sref, $x[0]);
- die "gzip->deflate: $err" if $err != Z_OK;
+ 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});
+ $ctx->{base_url} // do {
+ $ctx->zmore(html_top($ctx));
+ $ctx->{base_url} = base_url($ctx);
+ };
+ $ctx->zmore($$sref) if $sref;
+ my $bdy = $ctx->zflush(_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