ehcache

net.sf.ehcache.constructs.web
Class ResponseUtil

java.lang.Object
  extended by net.sf.ehcache.constructs.web.ResponseUtil

public final class ResponseUtil
extends java.lang.Object

A collection of response processing utilities, which are shared between 2 or more filters

Version:
$Id: ResponseUtil.java 519 2007-07-27 07:11:45Z gregluck $
Author:
Greg Luck

Method Summary
static void addGzipHeader(javax.servlet.http.HttpServletResponse response)
          Adds the gzip HTTP header to the response.
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

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 ResponseHeadersNotModifiableException
Adds the gzip HTTP header to the response. This is need 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:
ResponseHeadersNotModifiableException - 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 set header is ignored.

ehcache