From 0ff8c4f7e0815a0aa2e9935dd07ae446ce83c906 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 10 Sep 2022 08:16:58 +0000 Subject: [PATCH] viewvcs: use shorter and simpler ctx->html_done We only return 200s for any response large enough to warrant ->html_done, so we can just assume it. ViewVCS can also take advantage of it with some tweaking to avoid an extra method dispatch. --- lib/PublicInbox/View.pm | 2 +- lib/PublicInbox/ViewVCS.pm | 5 +---- lib/PublicInbox/WwwStream.pm | 8 ++++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/View.pm b/lib/PublicInbox/View.pm index 1cbc62be..c6fd05cc 100644 --- a/lib/PublicInbox/View.pm +++ b/lib/PublicInbox/View.pm @@ -61,7 +61,7 @@ sub no_over_html ($) { ${$ctx->{obuf}} .= '
'; } html_footer($ctx, $eml); - $ctx->html_done(200); + $ctx->html_done; } # public functions: (unstable) diff --git a/lib/PublicInbox/ViewVCS.pm b/lib/PublicInbox/ViewVCS.pm index ed4a6454..d3ac1a7d 100644 --- a/lib/PublicInbox/ViewVCS.pm +++ b/lib/PublicInbox/ViewVCS.pm @@ -253,10 +253,7 @@ possible to have multiple root commits when merging independent histories. Every commit references one top-level tree object. EOM - $x = $ctx->zflush($x, $ctx->_html_end); - my $res_hdr = delete $ctx->{-res_hdr}; - push @$res_hdr, 'Content-Length', length($x); - delete($ctx->{env}->{'qspawn.wcb'})->([200, $res_hdr, [$x]]); + delete($ctx->{env}->{'qspawn.wcb'})->($ctx->html_done($x)); } sub stream_patch_parse_hdr { # {parse_hdr} for Qspawn diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index 1fc213d4..c23668a4 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -167,12 +167,12 @@ sub getline { $ctx->zflush(_html_end($ctx)); } -sub html_done ($$) { - my ($ctx, $code) = @_; - my $bdy = $ctx->zflush(_html_end($ctx)); +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); - [ $code, $res_hdr, [ $bdy ] ] + [ 200, $res_hdr, [ $bdy ] ] } sub html_oneshot ($$;@) { -- 2.44.0