expressjs / expressjs/compression

Express returns a non-compliant HTTP/206 response when gzip is enabled

Open
#185 9 comments 1 reaction 0 assignees View on GitHub
Dominant language
JavaScript
Stars
2.8k
Forks
255
Avg merge
3d 15h
Merged PRs (30d)
3

Description

CDNs (mostly Azure Front Door) is using [HTTP Range Requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests) to retrieve data from Origin when caching enabled.

Express should ignore `Range: ` requests header when `gzip` compression is in place since Express is unable to respond a `HTTP/206` compliant answer with the right computed `Content-Range` header in the response that is taking the compressed data length into account.

A fair compliant workaround is to, in that very case of compression where computing `Content-Range` values would be too complex, ignore client's `Range:` header in the request, and answer the whole compressed content in a HTTP/200 response.

Handling `Range: ` headers is optional so answering a `HTTP/200` is OK.

Answering a `HTTP/206` with wrong `Content-Range` values is notOK.

Meanwhile another workaround is to disable compression and make CDN handle it, or disable CDN caching, however it would be fair to expect Express to return a compliant HTTP response in any case.

References:

[RFC7233](https://datatracker.ietf.org/doc/html/rfc7233)

Details and highlighting Express behavior:

https://github.com/DanielLarsenNZ/nodejs-express-range-headers

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.