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-Status: No, score=-4.0 required=3.0 tests=ALL_TRUSTED,BAYES_00 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 692EF1F954 for ; Sun, 5 Jul 2020 23:28:15 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 39/43] wwwtext: simplify gzf_maybe use Date: Sun, 5 Jul 2020 23:27:55 +0000 Message-Id: <20200705232759.3161-40-e@yhbt.net> In-Reply-To: <20200705232759.3161-1-e@yhbt.net> References: <20200705232759.3161-1-e@yhbt.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: gzf_maybe always returns a GzipFilter object, even if it uses CompressNoop. We can also use ->zflush instead of ->translate(undef) here for the final bit. --- lib/PublicInbox/WwwText.pm | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/WwwText.pm b/lib/PublicInbox/WwwText.pm index 08691684d..a691e2d8e 100644 --- a/lib/PublicInbox/WwwText.pm +++ b/lib/PublicInbox/WwwText.pm @@ -38,16 +38,13 @@ sub get_text { } my $env = $ctx->{env}; if ($raw) { - my $body; - if (my $gzf = $code == 200 ? gzf_maybe($hdr, $env) : undef) { - my $zbuf = $gzf->translate($txt); - undef $txt; - $body = [ $zbuf .= $gzf->translate(undef) ]; - } else { - $body = [ $txt ]; + if ($code == 200) { + my $gzf = gzf_maybe($hdr, $env); + $txt = $gzf->translate($txt); + $txt .= $gzf->zflush; } - $hdr->[3] = bytes::length($body->[0]); - return [ $code, $hdr, $body ] + $hdr->[3] = bytes::length($txt); + return [ $code, $hdr, [ $txt ] ] } # enforce trailing slash for "wget -r" compatibility