-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
GZipHandler does not play nice with other handlers in HandlerCollection #7858
Comments
What is the declared context path of your ServletContextHandler ? |
"/" - The request in question never touches the ServletContextHandler. |
If your
Why do this?
Also, mixing The most common reason people attempt to set up ResourceHandler and ServletContextHandler combined, is because they have a Servlet (usually a REST lib) set to answer on root context. This is an anti-pattern, mixing static content and REST on the same root url. If you move your REST support url to a different host (eg: |
Thank you, and yes, I am aware of the fact that the construction is weird. (Historical reason). |
When you see If you are using a handler collection, the Examples: |
In your setup, if the initial |
Thank you again for the followup, and yes I'm aware of all the points you are making - we have already restructured our handler configuration . |
@JensGabe I agree that there is a bug there. Regardless of if your setup is correct/best or not, I don't think GzipHandler should act in the way you are describing. If the request has been handled by a prior ResourceHandler, then the GzipHandler should be a noop. |
I mocked this layout up, and the HandlerCollection (top level) does not call the GzipHandler if the ResourceHandler before it handled the request. |
I simplified out initial weird configuration to this oneliner - GZipHandler#handle is called on every request:
|
A more reliable setup, use HandlerList instead of HandlerCollection
|
Signed-off-by: Joakim Erdfelt <[email protected]>
Opened PR #7872 (for |
Signed-off-by: Joakim Erdfelt <[email protected]>
* Better conditional logic in GzipHandler * Correct test expectations Signed-off-by: Joakim Erdfelt <[email protected]>
* Better conditional logic in GzipHandler * Correct test expectations Signed-off-by: Joakim Erdfelt <[email protected]>
* Better conditional logic in GzipHandler * Correct test expectations * Use super.handle() where appropriate Signed-off-by: Joakim Erdfelt <[email protected]>
Jetty version(s)
Jetty 11.0.2
Java version/vendor
(use: java -version)
Temurin 17.02+8
OS type/version
Windows Server 2016
Description
Handler configuration:
The GZIPHandler is configured with minSize=1024 and includes javascript and other text files.
When requesting a root static file with a size over 96K, the GZIPHandler will gzip the part of the content which exceeds 96K - the first 96K of the content is plain text, and the remainder looks GZipped.
(The repsonse content length matched the actual file length, and the browser (chrome) report error content-length mismatch)
If the root static file is a pre-zipped file, it works fine, also for size > 96K.
If the same static file is requested via the /foo resource handler, it works fine.
On my Developer setup (Windows 10, same Java) it works fine - I cannot get it to fail as on the Server installation.
Checking the source code of the various handlers, I noticed that all the handlers i used, except GZipHandler starts with:
Reconfiguring handler configuration to use HandlerList instead or move the ResourceHandler into a wrapped ContextHandler in the ContextHandlerCollection will both fix the issue for me.
It seems like the GZipHandler or a buffer handling deeper in the output handling is not working as intended if it is called after another handler handles the request.
How to reproduce?
See description.
The text was updated successfully, but these errors were encountered: