Skip to content

Conversation

@ryanfowler
Copy link
Contributor

This PR fixes broken range requests when using the compression middleware by skipping response body compression when the Content-Range header is present in the response. It also strips the Accept-Ranges response header when performing compression.

Motivation

Fixes #416

Solution

I believe the correct behaviour for this library is to pass along the Range request header, and skip compression if the Content-Range response header is present. This will allow range requests if the wrapped services support them, and skip compression in that circumstance to avoid corruption. If the user would rather compress everything, they can disallow range requests by stripping out the Range request header in an earlier middleware.

Notably, this is how a prominent Go library handles range requests and compression:

Copy link
Member

@jplatte jplatte left a comment

Choose a reason for hiding this comment

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

Thanks! Can you add a changelog entry?

@ryanfowler
Copy link
Contributor Author

@jplatte thanks for the review! Added the comment and changelog entry 😄

@jplatte jplatte enabled auto-merge (squash) January 26, 2024 21:20
@jplatte jplatte merged commit 9d0a53d into tower-rs:main Jan 26, 2024
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.

CompressionLayer breaks range requests, violating RFC 7233

2 participants