From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-4.2 required=3.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id EDF741F620 for ; Sat, 10 Sep 2022 08:18:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=80x24.org; s=selector1; t=1662797933; bh=U4TOGY7FE3nR3/e9HTCp8B9pSgEsNQcOjTlHEExIu8E=; h=From:To:Subject:Date:In-Reply-To:References:From; b=O6HvX4lGMQnDLiQPW8w9URREDOeoBwVrnEarVlIQwzDORBGMqih8M/5DCVNzhVCRX cyzSgoykv0C+4+TdqQnj1YS94kWuSbaJJZILUhunmL62Zy4AzM9cYcyCgLwuHvEtNg pTlv3kv4mk2xHUVDbJw90HesQCTeJ0z57yxci9OI= From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 07/38] viewvcs: use shorter and simpler ctx->html_done Date: Sat, 10 Sep 2022 08:16:58 +0000 Message-Id: <20220910081729.2011934-8-e@80x24.org> In-Reply-To: <20220910081729.2011934-1-e@80x24.org> References: <20220910081729.2011934-1-e@80x24.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: 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 ($$;@) {