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

Fixes Vert.x issue 5371 #5372

Merged
merged 4 commits into from
Oct 25, 2024
Merged

Fixes Vert.x issue 5371 #5372

merged 4 commits into from
Oct 25, 2024

Conversation

bjornhusberg
Copy link
Contributor

@bjornhusberg bjornhusberg commented Oct 24, 2024

Motivation

The Http2 server-implementation handles content encoding differently compared to the Http1.x server-implementation, which leads to issues.

Http1.x:
The HttpContentCompressor determines the encoding based on the Accept-Encoding header right before writing the headers. If the request handler has already set a Content-Encoding header there will be no further encoding and if the Content-Encoding header is set to "identity" the header is removed by HttpChunkContentCompressor and the response is returned as-is.

Http2:
The encoding is determined already when setting up the stream in Http2ServerConnection and is then passed down to Http2ServerRequest and Http2ServerResponse where it is set using the Content-Encoding-header. The header content is later picked up by the CompressorHttp2ConnectionEncoder which compresses the response accordingly.

While the Http1.x-implementation works fine the Http2-implementation leads to two problems:

  1. If the response is already encoded by the request handler and the Content-Encoding header has been set accordingly, the CompressorHttp2ConnectionEncoder picks up the encoding and encodes the response again, resulting in garbage returned to the client.

  2. If the Content-Encoding is explicitly set to "identity", the response is not compressed by the CompressorHttp2ConnectionEncoder but the Content-Encoding holding "identity" leaks out to the client. This is unnecessary and leads to confusion for some clients.

Changes

Removes the setting of the Content-Encoding header in Http2ServerResponse.

  • Change motivation: Setting the header in one place and performing the compression in another makes it difficult to handle scenarios where the header is set by other code. For instance a request handler. Setting the encoding in the HttpServerResponse is also not the way it's done in the Http1-implementation.
  • Actual changes: Removed the setting of the header from Http2ServerResponse. After that, the contentEncoding variable could be removed from the Http2ServerResponse, the Http2ServerRequest and the Push class and no longer needed to be determined in the Http2ServerConnection.initStream or Http2ServerConnection.doSendPush.

Extended the CompressorHttp2ConnectionEncoder with a new VertxCompressorHttp2ConnectionEncoder.

  • Change motivation: The new encoder determines the content-encoding right before writing the headers, similar to how it's done in HttpContentCompressor. This makes it possible to handle the case where the payload has already been encoded by a request handler or explicitly disabled using Content-Encoding: identity.
  • Actual changes: Added a VertxCompressorHttp2ConnectionEncoder that determines if the payload should be compressed just before writing the headers. If content-encoding has already been set or could not be determined the compressor encoder is skipped. If the Content-Encoding header is set to "identity" it is removed.

Adds two new tests in Http2ServerTest that verifies the issues described in the GitHub issue.

Outcome

The two issues described are solved and tests are green. :)

#5371

@vietj vietj added this to the 5.0.0 milestone Oct 24, 2024
@vietj vietj added the bug label Oct 24, 2024
@vietj
Copy link
Member

vietj commented Oct 24, 2024

can you describe in your comment what is the result of the changes you did as outline in the original issue fixed ?

Motivation: blah
Changes: blah
Result: blah

@vietj
Copy link
Member

vietj commented Oct 24, 2024

the content of the issue was great and very explanatory, it deserves to be used as comment following the pattern outline above

@vietj
Copy link
Member

vietj commented Oct 25, 2024

@bjornhusberg tests don't see to pass, can you have a look ?

@bjornhusberg
Copy link
Contributor Author

@vietj Tests are updated

@bjornhusberg
Copy link
Contributor Author

Rerun?

@vietj
Copy link
Member

vietj commented Oct 25, 2024

@bjornhusberg did that indeed, flaky test

@vietj vietj merged commit 46e8167 into eclipse-vertx:master Oct 25, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants