]> Sergey Matveev's repositories - public-inbox.git/commitdiff
{gzip,noop}filter: ->zmore returns undef, always
authorEric Wong <e@yhbt.net>
Sun, 5 Jul 2020 23:27:25 +0000 (23:27 +0000)
committerEric Wong <e@yhbt.net>
Mon, 6 Jul 2020 20:01:15 +0000 (20:01 +0000)
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
lib/PublicInbox/NoopFilter.pm
lib/PublicInbox/WwwListing.pm

index d2eb4e6643e500f7a77cdf27aecb75380be8377c..0fbb4476aabf637d82af5f5f3abf2ff47de1976c 100644 (file)
@@ -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
index b9c00ff7a13e14fe9f59675ad37747cde6efda58..a97dbde6456fd558c896367207e26a1b34396661 100644 (file)
@@ -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;
index 780c97e913b22a9d2427aa4d7cd5a3c80f4a65ea..d641e6d5cf6d38c558147e03db002dd3db640d9c 100644 (file)
@@ -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('<html><head><title>' .
+       $gzf->zmore('<html><head><title>' .
                                'public-inbox listing</title>' .
                                '</head><body><pre>');
        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('</pre><hr><pre>'.
+       my $out = $gzf->zflush('</pre><hr><pre>'.
                                PublicInbox::WwwStream::code_footer($env) .
                                '</pre></body></html>');
        $h->[3] = bytes::length($out);