]> git.ipfire.org Git - thirdparty/public-inbox.git/commitdiff
www: reduce likelyhood of undefined HTTP header values
authorEric Wong <e@80x24.org>
Fri, 31 Oct 2025 20:35:05 +0000 (20:35 +0000)
committerEric Wong <e@80x24.org>
Sun, 2 Nov 2025 19:52:21 +0000 (19:52 +0000)
I'm not seeing how it's possible, but it appears HTTP.pm
occasionally warns on undefined HTTP headers in its responses
and is generating invalid HTTP headers.

lib/PublicInbox/WwwListing.pm
lib/PublicInbox/WwwStream.pm

index 59b4741932076f42726d6d78385dfa8d23193189..c9c9338ca2d43d12fedf421137d5af0912b08627 100644 (file)
@@ -210,8 +210,7 @@ EOM
 
 sub psgi_triple {
        my ($ctx) = @_;
-       my $h = [ 'Content-Type', 'text/html; charset=UTF-8',
-                       'Content-Length', undef ];
+       my $h = [ 'Content-Type', 'text/html; charset=UTF-8' ];
        my $gzf = gzf_maybe($h, $ctx->{env});
        my $zfh = $gzf->zfh;
        print $zfh '<html><head><title>public-inbox listing</title>',
@@ -240,7 +239,7 @@ sub psgi_triple {
 qq(This is a listing of public inboxes, see the `mirror' link of each inbox
 for instructions on how to mirror all the data and code on this site.) .
                        '</pre></body></html>');
-       $h->[3] = length($out);
+       push @$h, 'Content-Length', length($out);
        [ $code, $h, [ $out ] ];
 }
 
index 8d32074fbefa2a9e6b06c3a38d941799d1a8dfb7..b3dfe341b4aab4cc108fa0c24bb398f809b74c24 100644 (file)
@@ -231,8 +231,7 @@ sub html_done ($;@) {
 
 sub html_oneshot ($$;@) {
        my ($ctx, $code) = @_[0, 1];
-       my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8',
-               'Content-Length' => undef ];
+       my $res_hdr = [ 'Content-Type' => 'text/html; charset=UTF-8' ];
        bless $ctx, __PACKAGE__;
        $ctx->{gz} = PublicInbox::GzipFilter::gz_or_noop($res_hdr, $ctx->{env});
        my @top;
@@ -241,7 +240,7 @@ sub html_oneshot ($$;@) {
                $ctx->{base_url} = base_url($ctx);
        };
        my $bdy = $ctx->zflush(@top, @_[2..$#_], _html_end($ctx));
-       $res_hdr->[3] = length($bdy);
+       push @$res_hdr, 'Content-Length', length($bdy);
        [ $code, $res_hdr, [ $bdy ] ]
 }