FU: Improve merging of "Vary" response headers + debug header listing

This commit is contained in:
Yorhel 2025-04-20 11:40:27 +02:00
parent f2294a709a
commit 1594006739
2 changed files with 10 additions and 8 deletions

7
FU.pm
View file

@ -863,14 +863,12 @@ sub _finalize {
$r->{resbody} = '';
} else {
my @vary = ref $r->{reshdr}{vary} eq 'ARRAY' ? $r->{reshdr}{vary}->@* : defined $r->{reshdr}{vary} ? ($r->{reshdr}{vary}) : ();
if (($hasgzip || $hasbrotli) && length($r->{resbody}) > 256
&& !defined $r->{reshdr}{'content-encoding'}
&& FU::compress_mimes->{$r->{reshdr}{'content-type'}}
) {
$r->{reshdr}{'vary'} = ($r->{reshdr}{'vary'} ? $r->{reshdr}{'vary'}.', ' : '').'accept-encoding'
if ($r->{reshdr}{'vary'}||'') !~ /accept-encoding/i;
push @vary, 'accept-encoding';
if ($hasbrotli && ($r->{hdr}{'accept-encoding'}||'') =~ /\bbr\b/) {
$r->{resbody} = FU::Util::brotli_compress(6, $r->{resbody});
$r->{reshdr}{'content-encoding'} = 'br';
@ -880,6 +878,7 @@ sub _finalize {
$r->{reshdr}{'content-encoding'} = 'gzip';
}
}
$r->{reshdr}{vary} = @vary ? join ', ', @vary : undef;
$r->{reshdr}{'content-length'} = length $r->{resbody};
$r->{resbody} = '' if (fu->method//'') eq 'HEAD';
}

View file

@ -75,10 +75,13 @@ my @tabs = (
};
h2_ 'Headers';
table_ sub {
for my $k (sort keys $r->{reshdr}->%*) {
my $v = $r->{reshdr}{$k};
tr_ sub {
td_ $k;
td_ $_;
td_ $r->{reshdr}{$_};
} for sort keys $r->{reshdr}->%*;
} for !defined $v ? () : ref $v ? @$v : ($v);
}
};
('Response')
},