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 GzipHandler issues with HttpConnector mode enabled on Jetty 9.4 #308

Merged
merged 2 commits into from
Nov 18, 2024

Conversation

lachlan-roberts
Copy link
Collaborator

for the Jetty 9.4 path the GzipHandler is modifying headers of the base Request.

However this is occurring after the JettyRequestAPIData has already copied the headers and filtered out GAE specific headers from what the application receives, so any modifications to the Request headers by GzipHandler were not seen by the application.

The fix is to insert the GzipHandler before the JettyHttpHandler in the handler chain.

This is not an issue with the Jetty 12 path as both the GzipHandler and the JettyHttpHandler wrap the request to modify the headers.

I added GzipHandlerTest to test this for jetty94, ee8 and ee10 code paths.

@maigovannon
Copy link
Collaborator

This is not an issue with the Jetty 12 path as both the GzipHandler and the JettyHttpHandler wrap the request to modify the headers.

Could you explain more on this? I see that the logic in the Jetty12 has the same ordering of handlers as the current order in Jetty9 so how would the ordering not be an issue there? Please explain on what the additional wrapping mentioned does for Jetty 12 which is not done for Jetty9?

In case the ordering there doesn't matter, I feel having the same ordering of handlers can be maintained between the Jetty9 and Jetty12 code for uniformity and readability. Otherwise future readers might get confused.

Comment on lines +122 to +126
// If it has a HttpHeader it is one of the standard headers so won't match any appengine specific header.
if (field.getHeader() != null) {
fields.add(field);
continue;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Actually even without this logic, a non-AE header should have been added by the line below no? Am I missing something here since the switch is only to certain certain flags and not to prevent addition of fields?
  2. If my above statement is wrong and that we still need to have this check, can we please this condition along with that line mentioned there? Just to have a more consistent flow of readability on what all fields are getting added?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That is correct, it is still correct without this.

This is just an optimization so that we can skip the rest of the logic in the loop as we know straight away it will not match any of these headers.

@lachlan-roberts
Copy link
Collaborator Author

Could you explain more on this? I see that the logic in the Jetty12 has the same ordering of handlers as the current order in Jetty9 so how would the ordering not be an issue there? Please explain on what the additional wrapping mentioned does for Jetty 12 which is not done for Jetty9?

The Jetty 9.4 handlers have the signature void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response). In the JettyHttpHandler we wrap the request with JettyRequestAPIData, which copies over the headers from the Request baseRequest which can filter out certain private headers so the application can't see them.

The GzipHandler in 9.4 modifies the headers in Request baseRequest, so if the JettyHttpHandler has already run, then the headers have already been copied and no change will be seen by the application when Content-Encoding: gzip is removed.

In Jetty 12 the headers are modified by wrapping the request and overriding getHeaders(). So there is no HttpServletRequest yet just a single Jetty Core request, and both the GzipHandler and the JettyHttpHandler act only on the Jetty core Request. And later in the chain it will reach the WebAppContext will it be converted into a servlet request.

Copy link
Collaborator

@ludoch ludoch left a comment

Choose a reason for hiding this comment

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

@maigovannon will do the integration process after final review

@lachlan-roberts lachlan-roberts merged commit 646d260 into main Nov 18, 2024
7 checks passed
@lachlan-roberts lachlan-roberts deleted the gzip-headers-jetty94 branch November 18, 2024 04:03
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.

3 participants