From b9f8ce2686cc120db08a680eab3e849bff23e19f Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 31 Oct 2025 20:35:05 +0000 Subject: [PATCH] www: reduce likelyhood of undefined HTTP header values 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 | 5 ++--- lib/PublicInbox/WwwStream.pm | 5 ++--- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/PublicInbox/WwwListing.pm b/lib/PublicInbox/WwwListing.pm index 59b474193..c9c9338ca 100644 --- a/lib/PublicInbox/WwwListing.pm +++ b/lib/PublicInbox/WwwListing.pm @@ -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 'public-inbox listing', @@ -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.) . ''); - $h->[3] = length($out); + push @$h, 'Content-Length', length($out); [ $code, $h, [ $out ] ]; } diff --git a/lib/PublicInbox/WwwStream.pm b/lib/PublicInbox/WwwStream.pm index 8d32074fb..b3dfe341b 100644 --- a/lib/PublicInbox/WwwStream.pm +++ b/lib/PublicInbox/WwwStream.pm @@ -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 ] ] } -- 2.47.3