Skip to content

Conversation

robbtraister
Copy link

Description

The body-parser package supports the content-encoding header on the request (See here). When reconstructing the body for proxied requests that have already been parsed, we should respect the content-encoding header and preserve the original compression algorithm.

Motivation and Context

Without this patch, an encoded request will fail when the upstream server attempts to read it due to a mismatch between the compression algorithm reported and the actual payload received. An alternative approach would be to remove the content-encoding header from the proxied request, but this seems more appropriate.

How has this been tested?

I added a unit test to verify that the reconstructed body is encoded as expected.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.

proxyData = zlib.gzipSync(proxyData);
break;
case 'zstd':
proxyData = zlib.zstdCompressSync(proxyData);
Copy link
Owner

@chimurai chimurai Sep 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

zlib.zstdCompressSync will throw in older Node versions:

Added in: v23.8.0, v22.15.0

https://nodejs.org/api/zlib.html#zlibzstdcompresssyncbuffer-options

Can you remove zstd support? since it is still experimental

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing. I noticed that body-parser only supports br, deflate, and gzip, but I thought might as well be more complete if possible. But I agree that better stability is more important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants