Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support zero-length compressed request and response messages on Node.js #893

Merged
merged 2 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/connect-node-test/src/compression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ describe("compression", () => {
const equal = payload.every((value, index) => b[index] === value);
expect(equal).toBeTrue();
});
it("should decompress zero-length payload", async () => {
const b = await compression.decompress(new Uint8Array(0), 0xffffffff);
expect(b.byteLength).toBe(0);
});
it("should raise resource_exhausted if maxReadBytes exceeded", async () => {
try {
await compression.decompress(payloadCompressed, 2);
Expand Down
6 changes: 6 additions & 0 deletions packages/connect-node/src/compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const compressionGzip: Compression = {
return gzip(bytes, {});
},
decompress(bytes, readMaxBytes) {
if (bytes.length == 0) {
return Promise.resolve(new Uint8Array(0));
}
return wrapZLibErrors(
gunzip(bytes, {
maxOutputLength: readMaxBytes,
Expand All @@ -56,6 +59,9 @@ export const compressionBrotli: Compression = {
return brotliCompress(bytes, {});
},
decompress(bytes, readMaxBytes) {
if (bytes.length == 0) {
return Promise.resolve(new Uint8Array(0));
}
return wrapZLibErrors(
brotliDecompress(bytes, {
maxOutputLength: readMaxBytes,
Expand Down
2 changes: 2 additions & 0 deletions packages/connect/src/protocol/compression.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export interface Compression {
/**
* Decompress a chunk of data.
*
* A zero-length chunk is acceptable, and will return a zero-length result.
*
* Raises a ConnectError with Code.InvalidArgument if the decompressed
* size exceeds readMaxBytes.
*/
Expand Down