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 893C81F8EE for ; Sun, 5 Jul 2020 23:28:07 +0000 (UTC) From: Eric Wong To: meta@public-inbox.org Subject: [PATCH 09/43] {gzip,noop}filter: ->zmore returns undef, always Date: Sun, 5 Jul 2020 23:27:25 +0000 Message-Id: <20200705232759.3161-10-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: This simplifies callers, as witnessed by the change to WwwListing. It adds overhead to NoopFilter, but NoopFilter should see little use as nearly all HTTP clients request gzip. --- lib/PublicInbox/GzipFilter.pm | 2 +- lib/PublicInbox/NoopFilter.pm | 19 +++++++++++++++---- lib/PublicInbox/WwwListing.pm | 8 ++++---- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/lib/PublicInbox/GzipFilter.pm b/lib/PublicInbox/GzipFilter.pm index d2eb4e664..0fbb4476a 100644 --- a/lib/PublicInbox/GzipFilter.pm +++ b/lib/PublicInbox/GzipFilter.pm @@ -73,7 +73,7 @@ sub zmore { my $self = $_[0]; # $_[1] => input my $err = $self->{gz}->deflate($_[1], $self->{zbuf}); die "gzip->deflate: $err" if $err != Z_OK; - ''; + undef; } # flushes and returns the final bit of gzipped data diff --git a/lib/PublicInbox/NoopFilter.pm b/lib/PublicInbox/NoopFilter.pm index b9c00ff7a..a97dbde64 100644 --- a/lib/PublicInbox/NoopFilter.pm +++ b/lib/PublicInbox/NoopFilter.pm @@ -4,10 +4,21 @@ package PublicInbox::NoopFilter; use strict; -sub new { bless \(my $ignore), __PACKAGE__ } +sub new { bless \(my $self = ''), __PACKAGE__ } # noop workalike for PublicInbox::GzipFilter methods -sub translate { $_[1] // '' } -sub zmore { $_[1] } -sub zflush { $_[1] // '' } +sub translate { + my $self = $_[0]; + my $ret = $$self .= ($_[1] // ''); + $$self = ''; + $ret; +} + +sub zmore { + ${$_[0]} .= $_[1]; + undef; +} + +sub zflush { translate($_[0], $_[1]) } + 1; diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm index 780c97e91..d641e6d5c 100644 --- a/lib/PublicInbox/WwwListing.pm +++ b/lib/PublicInbox/WwwListing.pm @@ -109,7 +109,7 @@ sub html ($$) { my $h = [ 'Content-Type', 'text/html; charset=UTF-8', 'Content-Length', undef ]; my $gzf = gzf_maybe($h, $env) || PublicInbox::NoopFilter::new(); - my $out = $gzf->zmore('' . + $gzf->zmore('<html><head><title>' . 'public-inbox listing' . '
');
 	my $code = 404;
@@ -122,11 +122,11 @@ sub html ($$) {
 
 		my $tmp = join("\n", map { ibx_entry(@$_, $env) } @$list);
 		my $l = PublicInbox::Linkify->new;
-		$out .= $gzf->zmore($l->to_html($tmp));
+		$gzf->zmore($l->to_html($tmp));
 	} else {
-		$out .= $gzf->zmore('no inboxes, yet');
+		$gzf->zmore('no inboxes, yet');
 	}
-	$out .= $gzf->zflush('

'.
+	my $out = $gzf->zflush('

'.
 				PublicInbox::WwwStream::code_footer($env) .
 				'
'); $h->[3] = bytes::length($out);