Skip to content

Commit

Permalink
core(network-request): recognize zstd compression algorithm (#15883)
Browse files Browse the repository at this point in the history
  • Loading branch information
selfisekai authored and adamraine committed Apr 5, 2024
1 parent c4e0d66 commit 4a81f2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/lib/network-request.js
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ class NetworkRequest {
/^content-encoding$/i,
/^x-content-encoding-over-network$/i,
];
const compressionTypes = ['gzip', 'br', 'deflate'];
const compressionTypes = ['gzip', 'br', 'deflate', 'zstd'];
return record.responseHeaders.some(header =>
patterns.some(p => header.name.match(p)) && compressionTypes.includes(header.value)
);
Expand Down
18 changes: 18 additions & 0 deletions core/test/lib/network-request-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,22 @@ describe('NetworkRequest', () => {
})).toBe(false);
});
});

describe('#isContentEncoded', () => {
const isContentEncoded = NetworkRequest.isContentEncoded;

it('correctly identifies no compression', () => {
expect(isContentEncoded({responseHeaders: []})).toBe(false);
});
it('correctly identifies brotli', () => {
expect(isContentEncoded({
responseHeaders: [{name: 'content-encoding', value: 'br'}],
})).toBe(true);
});
it('correctly identifies zstd', () => {
expect(isContentEncoded({
responseHeaders: [{name: 'content-encoding', value: 'zstd'}],
})).toBe(true);
});
});
});

0 comments on commit 4a81f2c

Please sign in to comment.