Skip to content

gzip compression in DispatcherServlet [SPR-11714] #16336

Closed

Description

@spring-projects-issues

Christopher Smith opened SPR-11714 and commented

A very old issue to add gzip compression to the Web MVC framework was closed in favor of configuring compression at the server level, but I'd like to revisit the issue.

I've been working on adding compression as a configuration option to Spring Boot, and configuring it for either Tomcat or Jetty requires an explicit list of every content type that is eligible for compression, a list that conspicuously does not by default include application/json in either case, and can't take wildcards to compress application/*+json/xml. I've dug more into Tomcat, but configuring it requires protocol-specific casts to get to the config methods, and configuring the eligible content types is not thread safe (and in a Spring context can't reliably be done before publication). Additionally, the newer NIO connectors on Jetty and Tomcat can both have some collisions with compression.

I suggest inserting a compressing wrapper around the HttpServletResponse in the view.render call in the DispatcherServlet. Would this feature be considered "on-topic" at this point?


Affects: 4.0.3

Reference URL: #5514

This issue is a sub-task of #16413

Issue Links:

1 votes, 11 watchers

Activity

  1. spring-projects-issues commented on Apr 21, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    This isn't a bad fit with our 4.1 web theme, actually: It's all about web performance options such as cache control and resource pipelining...

    brianclozel, I'm assigning this to you since you're the owner of the related issues for 4.1 as well.

    Juergen

  2. spring-projects-issues commented on Apr 21, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Christopher Smith commented

    Then I'll add a note that I'd love for the resource framework to be able to handle precompressed copies "intelligently" (e.g., serve logo.svg.gz or even logo.svgz for a request for logo.svg with gzip encoding). Is that something that would be a separate (re-raised) JIRA issue?

  3. spring-projects-issues commented on Apr 22, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Brian Clozel commented

    Thanks Juergen Hoeller! Good idea.

    Christopher Smith we're already working on a related feature for resource handling (see #15561). I guess this could be implemented using a resource resolver, checking for resources that match the resource name + extensions variants. That's definitely a use case we'll look into.

    This feature is still work in progress at the moment, so expect some changes!

  4. spring-projects-issues commented on Apr 23, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Phil Webb commented

    Brian Clozel If this makes 4.1 and there are any Boot related changes required to enable it by default could you reopen spring-projects/spring-boot#683 ?

    Cheers!

  5. spring-projects-issues commented on Jul 28, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Christopher Smith commented

    Looks like this Patrick account is a spambot.

  6. spring-projects-issues commented on Jul 28, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Stéphane Nicoll commented

    Indeed, thanks for pinging us about it.

  7. spring-projects-issues commented on Mar 17, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Brian Clozel commented

    Hi Christopher Smith

    Here are some thoughts about this - let me know what you think!

    Current limitations with using Tomcat/Jetty

    I know that Tomcat and other servers aren't checking that mimetypes are compatible (in the sense of the related mime type/HTTP rfc) - but they do offer some flexibility regarding this:

    • right now Jetty is doing strict string comparisons, but it also allows configuring a whiletlist/blacklist for this. Jetty is also considering improvements for this support.
    • right now Tomcat is checking that the response content-type starts with one of the configured mimetypes. So configuring application/vnd.company would work for both application/vnd.company.v3+json and application/vnd.company.v2+xml

    Also, you're stuck with custom configuration files or APIs when configuring this.
    But when using boot, things get way easier to configure - see Boot's reference doc and spring.http.gzip.* configuration keys in the list of common application properties.

    Implementing this in Spring Framework

    While this is something we're considering for 4.2, I've found several drawbacks/challenges.

    1. servers usually implement that support with custom, low-level APIs to be really efficient. Doing the same thing at the DispatcherServlet level (or even the Filter level) would be less efficient
    2. because servlet 3.1 asyncIO support is a different beast, implementing this would only support regular IO style. This is an important drawback since serving gzipped, static resources with asyncIO support is definitely a win.
    3. HTTP/2 is around the corner, and content compression is included in the protocol itself

    Given the not so big limitations and the drawbacks listed above, I'm wondering if implementing this is actually worth it.

  8. spring-projects-issues commented on Mar 27, 2015

    @spring-projects-issues
    CollaboratorAuthor

    cemo koc commented

    I agree with Brian and believe that this issue is a better candidate for Spring Boot with low level capabilities.

    Note that Jetty deprecated support for GzipFilter and It is replaced with GzipHandler.

  9. spring-projects-issues commented on Mar 27, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Christopher Smith commented

    Given the move toward embedded containers, I think I agree with putting this in their configuration, especially as the resource system can already serve pre-gzipped static resources.

  10. spring-projects-issues commented on Mar 27, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Brian Clozel commented

    Let's close this issue for now, as this is much better supported by containers themselves.

  11. added
    status: declined
    in: web
    type: task
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: webstatus: declinedtype: task

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions