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

Fix Content-Length header removal after content compression #2863

Merged
merged 1 commit into from
Mar 6, 2024

Conversation

chrisvest
Copy link
Contributor

Motivation:
The ContentEncodingHttpServiceFilter is meant to remove the Content-Length header if it does compression, because any such header from earlier stages will be incorrect after compression. An incorrect Content-Length header will then cause down-stream clients to be confused and potentially stall, timeout, or produce an unexpected close error, when they don't receive their promised number of bytes (most likely fewer than promised, due to compression).

Modifications:
The ContentEncodingHttpServiceFilter incorrectly removed the Content-Length header from the request object, and this has been fixed so it now correctly removes the header from the response object. There was a test for this behavior, but the test wasn't actually hitting this code because it used a client that did not advertise support for compressed responses. The test has also been fixed, adding the case where the client supports compressed responses. We now test both that the Content-Length header is removed when the response is compressed, and that the header stays when the response is not compressed.

Result:
This fixes the issue showcased by #2862

Motivation:
The ContentEncodingHttpServiceFilter is meant to remove the `Content-Length` header if it does compression, because any such header from earlier stages will be incorrect after compression.
An incorrect `Content-Length` header will then cause down-stream clients to be confused and potentially stall, timeout, or produce an unexpected close error, when they don't receive their promised number of bytes (most likely fewer than promised, due to compression).

Modifications:
The ContentEncodingHttpServiceFilter incorrectly removed the `Content-Length` header from the _request_ object, and this has been fixed so it now correctly removes the header from the _response_ object.
There was a test for this behavior, but the test wasn't actually hitting this code because it used a client that did not advertise support for compressed responses.
The test has also been fixed, adding the case where the client supports compressed responses.
We now test both that the `Content-Length` header is removed when the response is compressed, and that the header stays when the response is not compressed.

Result:
This fixes the issue showcased by apple#2862
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

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

Great catch!

@Scottmitch Scottmitch merged commit dabaabc into apple:main Mar 6, 2024
15 checks passed
@chrisvest chrisvest deleted the compression-content-length branch March 6, 2024 23:38
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.

4 participants