Esempio n. 1
0
  /**
   * Method description
   *
   * @param request
   * @param response
   * @param chain
   * @throws IOException
   * @throws ServletException
   */
  @Override
  protected void doFilter(
      HttpServletRequest request, HttpServletResponse response, FilterChain chain)
      throws IOException, ServletException {
    if (WebUtil.isGzipSupported(request)) {
      GZipResponseWrapper wrappedResponse = new GZipResponseWrapper(response);

      chain.doFilter(request, wrappedResponse);
      wrappedResponse.finishResponse();
    } else {
      chain.doFilter(request, response);
    }
  }
Esempio n. 2
0
  /** {@inheritDoc} */
  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
      throws IOException, ServletException {

    if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {

      HttpServletRequest httpRequest = (HttpServletRequest) request;
      HttpServletResponse httpResponse = (HttpServletResponse) response;

      String acceptEncoding = httpRequest.getHeader("accept-encoding");
      if (acceptEncoding != null && acceptEncoding.contains("gzip")) {

        httpResponse.addHeader("Accept-Encoding", "gzip");
        httpResponse.addHeader("Vary", "Accept-Encoding");

        GZipResponseWrapper wrappedResponse = new GZipResponseWrapper(httpResponse);

        chain.doFilter(request, wrappedResponse);
        wrappedResponse.finishResponse();

        return;
      }
    }
    chain.doFilter(request, response);
  }