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

Skip compression for range requests #446

Merged
merged 5 commits into from
Jan 26, 2024

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
Collaborator

@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?

tower-http/src/compression/future.rs Show resolved Hide resolved
@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
11 checks passed
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