Class GZipResponseUtil

java.lang.Object
com.erudika.para.server.utils.GZipResponseUtil

public final class GZipResponseUtil extends Object
A collection of response processing utilities, which are shared between 2 or more filters.
Version:
$Id: ResponseUtil.java 744 2008-08-16 20:10:49Z gregluck $
Author:
Greg Luck
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addGzipHeader(javax.servlet.http.HttpServletResponse response)
    Adds the gzip HTTP header to the response.
    static void
    Adds the Vary: Accept-Encoding header to the response if needed.
    static boolean
    shouldBodyBeZero(javax.servlet.http.HttpServletRequest request, int responseStatus)
    Performs a number of checks to ensure response saneness according to the rules of RFC2616: If the response code is HttpServletResponse.SC_NO_CONTENT then it is illegal for the body to contain anything.
    static boolean
    shouldGzippedBodyBeZero(byte[] compressedBytes, javax.servlet.http.HttpServletRequest request)
    Checks whether a gzipped body is actually empty and should just be zero.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • shouldGzippedBodyBeZero

      public static boolean shouldGzippedBodyBeZero(byte[] compressedBytes, javax.servlet.http.HttpServletRequest request)
      Checks whether a gzipped body is actually empty and should just be zero. When the compressedBytes is EMPTY_GZIPPED_CONTENT_SIZE it should be zero.
      Parameters:
      compressedBytes - the gzipped response body
      request - the client HTTP request
      Returns:
      true if the response should be 0, even if it is isn't.
    • shouldBodyBeZero

      public static boolean shouldBodyBeZero(javax.servlet.http.HttpServletRequest request, int responseStatus)
      Performs a number of checks to ensure response saneness according to the rules of RFC2616:
      1. If the response code is HttpServletResponse.SC_NO_CONTENT then it is illegal for the body to contain anything. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.5
      2. If the response code is HttpServletResponse.SC_NOT_MODIFIED then it is illegal for the body to contain anything. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.3.5
      Parameters:
      request - the client HTTP request
      responseStatus - the responseStatus
      Returns:
      true if the response should be 0, even if it is isn't.
    • addGzipHeader

      public static void addGzipHeader(javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException
      Adds the gzip HTTP header to the response. This is needed when a gzipped body is returned so that browsers can properly decompress it.
      Parameters:
      response - the response which will have a header added to it. I.e this method changes its parameter
      Throws:
      javax.servlet.ServletException - Either the response is committed or we were called using the include method from a RequestDispatcher.include(javax.servlet.ServletRequest, javax.servlet.ServletResponse) method and the set header is ignored.
    • addVaryAcceptEncoding

      public static void addVaryAcceptEncoding(GZipServletResponseWrapper wrapper)
      Adds the Vary: Accept-Encoding header to the response if needed.
      Parameters:
      wrapper - response