Skip to content

Bug: compress() ignores Accept-Encoding qvalues and skips compression when identity is listed #5691

Description

@MohammedAlkindi

compress() should honour content-coding tokens: skip compression on Accept-Encoding: gzip;q=0, and compress on Accept-Encoding: gzip, identity. Both are currently inverted.

shouldCompress in packages/event-handler/src/http/middleware/compress.ts tests the raw header with String.prototype.includes, so 'gzip;q=0'.includes('gzip') is true and the q=0 exclusion is ignored, while 'gzip, identity'.includes('identity') is true and suppresses compression the client explicitly accepted. Per RFC 9110 a q=0 coding is not acceptable.

To reproduce, send either header to any route on a Router using compress() and read content-encoding on the response:

app.use(compress());
// Accept-Encoding: gzip;q=0        -> content-encoding: gzip   (should be absent)
// Accept-Encoding: gzip, identity  -> content-encoding: absent (should be gzip)

One fix is to parse the header into tokens and honour qvalues, reusing the existing encoding constants. Glad to open a PR if you want it done that way.

Version 2.35.0, npm, Node 22.x. Header parsing only, so runtime-independent.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions