Search code examples
postgetjettygzip

Why does jetty's GzipHandler default to only including GET requests?


I am configuring gzip compression for a server via Jetty, and there are PUT/POST endpoints whose response payloads I would like to compress. The default GzipHandler configuration for Jetty specifically only includes GET; that this is the default is documented, but I'm unable to find documentation as to why this is the default. Is there a downside to applying gzip when the method is non-GET?


Solution

  • The reason comes down to responses from PUT and POST are, in a general sense, not suitable for being put into a cache.

    GET was selected as the default back when gzip compression was first introduced, (and back before Jetty moved to Eclipse, back before Servlet 2.0, back when it was called the GzipFilter in Jetty) and in that era if the content couldn't be cached it wasn't compressed.

    Why?

    Well, back then using system resources to compress the same content over and over and over again was seen as a negative, it was more important to serve many requests vs a few optimized requests.

    The GzipHandler can be configured to use any method, even nonsensical ones like HEAD.

    Don't let a default value with historical reasons prevent you from using the GzipHandler, use it, configure it, and be happy.

    Feel free to file an issue requesting the defaults be changed at https://github.com/eclipse/jetty.project/issues