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
HTTP Response compression not working with request accept headers containing q= when using Jetty and WebFlux #18484
Comments
@MatthijsEM Are you able to share the sample application that you used to test this? |
I've tried to reproduce this issue and couldn't.
The following
And the logs are:
I'm probably missing something here. Could you share a sample application reproducing this issue? |
I was able to reproduce this using the exact setup you mentioned above (#18484 (comment)) but instead of a txt file I used a simple REST controller returning some JSON.
When calling this using
the server returns
which has compression and is correct. When calling this with
or more standard something like
the server returns
with no compression which is wrong. The server log will show
|
Thanks for the sample, I can see that now. In Jetty's
This means that Jetty will not remove any other media type parameter from the There's nothing we can do about that at the Spring Boot level. Could you create an issue in the Jetty project? Note that it seems that they don't want to expand features there too much, but I think that removing media type parameters before comparing with the whitelisted types is expected. In the meantime, WebFlux should not echo back the quality parameter in the response, I've created spring-projects/spring-framework#24239 to fix that. Thanks! |
TLDR; the server is not using compression when it should when the accept header with the mime-types contains
mime-type; q=x
.Tested this with Spring Boot 2.1.7 using Jetty and WebFlux. When using non-reactive (so no WebFlux) the problem does not occur.
With compression enabled the
application.properties
contains mime-types e.g.server.compression.mime-types=text/html,text/xml,text/plain,text/css,text/javascript,application/javascript,application/json
After the server has started using debugging the Jetty GzipHandler is added to the context and its list of included mime-types does contain the above list.
The exclude list (defaults) consists of
image/ief, image/vnd.wap.wbmp, image/jpeg, application/bzip2, image/x-portable-graymap, application/brotli, image/bmp, image/gif, image/x-icon, audio/midi, video/x-msvideo, image/x-xbitmap, application/x-rar-compressed, image/x-portable-bitmap, image/x-rgb, image/x-cmu-raster, application/gzip, audio/x-wav, audio/x-pn-realaudio, audio/basic, application/compress, audio/x-aiff, video/x.ms.asx, video/x.ms.asf, image/png, video/vnd.rn-realvideo, image/x-xwindowdump, image/jpeg2000, video/x-sgi-movie, audio/mpeg, image/xcf, video/mpeg, image/x-portable-pixmap, image/tiff, image/x-portable-anymap, image/x-xpixmap, application/zip, video/quicktime, application/x-xz, video/mp4
It looks like the GzipHandler is properly configured.
Browsers like Chrome and Edge will send an Accept header like
Accept: text/html, application/xhtml+xml, application/xml; q=0.9, */*; q=0.8
or
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
With trace logging enabled using the last Accept header the server log will print:
The last line already indicates that the response is not compressed while it should because the mime-type does not match. When debugging the GzipHandler
isMimeTypeGzipable
returns false because its trying to matchapplication/json;q=0.8
againstapplication/json
.The response is not compressed but it should be.
The q=x indicates a quality factor, the preference when sending multiple mime-types to the server so the server can choose based on the client preference. The suffix itself should not be passed to the GzipHandler which is not capable of handling it.
The text was updated successfully, but these errors were encountered: