Skip to content

Commit

Permalink
do not clobber existing middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
plicease committed May 10, 2024
1 parent 6c58c8f commit d9779fb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/Plack/Middleware/Zstandard.pm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ package Plack::Middleware::Zstandard {
push @vary, 'Accept-Encoding';
$h->set('Vary' => join(",", @vary));

# Do not clobber already existing encoding
return if $h->exists('Content-Encoding') && $h->get('Content-Encoding') ne 'identity';

return undef unless ($env->{HTTP_ACCEPT_ENCODING} // '') =~ /\bzstd\b/;

$h->set('Content-Encoding' => 'zstd');
Expand Down
26 changes: 26 additions & 0 deletions t/plack_middleware_zstandard.t
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,32 @@ subtest 'basic' => sub {

};

subtest 'do not clobber' => sub {

my $content = 'Hello World';
local @res = (
200, [
'Content-Type' => 'text/plain',
'Content-ENcoding' => 'foo',
], [
$content
]
);

req(
GET('/', 'Accept-Encoding' => 'zstd'),
res {
code 200;
header 'Content-Encoding' => 'foo';
header 'Vary', 'Accept-Encoding';
call content => 'Hello World';
},
);

note_debug();

};

subtest 'No accept' => sub {

my $content = 'Hello World';
Expand Down

0 comments on commit d9779fb

Please sign in to comment.