- my $self = bless {
- ctx => $ctx,
- base_url => base_url($ctx),
- }, __PACKAGE__;
- my @x = (_html_top($self), $sref ? $$sref : (), _html_end($self));
- my $len = 0;
- $len += bytes::length($_) for @x;
- [ $code, [
- 'Content-Type' => 'text/html; charset=UTF-8',
- 'Content-Length' => $len
- ], \@x ];
+ 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
+ }
+ };
+ 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);