net.sf.ehcache.constructs.web

Class ResponseUtil

public final class ResponseUtil extends Object

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

Version: $Id: ResponseUtil.java 108 2006-06-04 12:44:06Z gregluck $

Author: Greg Luck

Method Summary
static voidaddGzipHeader(HttpServletResponse response)
Adds the gzip HTTP header to the response.
static booleanshouldBodyBeZero(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 javax.servlet.http.HttpServletResponse#SC_NO_CONTENT then it is illegal for the body to contain anything.
static booleanshouldGzippedBodyBeZero(byte[] compressedBytes, HttpServletRequest request)
Checks whether a gzipped body is actually empty and should just be zero.

Method Detail

addGzipHeader

public static void addGzipHeader(HttpServletResponse response)
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 javax.servlet.RequestDispatcher#include(javax.servlet.ServletRequest, javax.servlet.ServletResponse) method and the set set header is ignored.

shouldBodyBeZero

public static boolean shouldBodyBeZero(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 javax.servlet.http.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 javax.servlet.http.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.

shouldGzippedBodyBeZero

public static boolean shouldGzippedBodyBeZero(byte[] compressedBytes, 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.