my ($ctx, $cb) = @_;
$ctx->{cb} = $cb;
$ctx->{base_url} = base_url($ctx);
+ $ctx->{-res_hdr} = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
+ $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($ctx->{-res_hdr},
+ $ctx->{env});
bless $ctx, __PACKAGE__;
}
$ctx->zflush(_html_end($ctx));
}
-sub html_oneshot ($$;$) {
- my ($ctx, $code, $sref) = @_;
+sub html_done ($;@) {
+ my $ctx = $_[0];
+ my $bdy = $ctx->zflush(@_[1..$#_], _html_end($ctx));
+ my $res_hdr = delete $ctx->{-res_hdr};
+ push @$res_hdr, 'Content-Length', length($bdy);
+ [ 200, $res_hdr, [ $bdy ] ]
+}
+
+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});
$ctx->{base_url} // do {
- $ctx->zmore(html_top($ctx));
+ $ctx->zadd(html_top($ctx));
$ctx->{base_url} = base_url($ctx);
};
- $ctx->zmore($$sref) if $sref;
- my $bdy = $ctx->zflush(_html_end($ctx));
+ my $bdy = $ctx->zflush(@_[2..$#_], _html_end($ctx));
$res_hdr->[3] = length($bdy);
[ $code, $res_hdr, [ $bdy ] ]
}
}
sub aresponse {
- my ($ctx, $code, $cb) = @_;
- my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
+ my ($ctx, $cb) = @_;
init($ctx, $cb);
- $ctx->psgi_response($code, $res_hdr);
+ $ctx->psgi_response(200, delete $ctx->{-res_hdr});
+}
+
+sub html_init {
+ my ($ctx) = @_;
+ $ctx->{base_url} = base_url($ctx);
+ my $h = $ctx->{-res_hdr} = ['Content-Type', 'text/html; charset=UTF-8'];
+ $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($h, $ctx->{env});
+ bless $ctx, __PACKAGE__;
+ $ctx->zadd(html_top($ctx));
}
1;