private ServletResponse getResponse(ServletRequest request, ServletResponse response) {
    if (response.isCommitted() || request.getAttribute(PROCESSED_ATTR) != null) {
      LOGGER.trace("No Compression: Response committed or filter has already been applied");
      return response;
    }

    if (!(response instanceof HttpServletResponse) || !(request instanceof HttpServletRequest)) {
      LOGGER.trace("No Compression: non http request/response");
      return response;
    }

    HttpServletResponse httpResponse = (HttpServletResponse) response;

    HttpServletRequest httpRequest = (HttpServletRequest) request;

    String acceptEncoding = httpRequest.getHeader(HTTP_ACCEPT_ENCODING_HEADER);

    String contentEncoding = getAppropriateContentEncoding(acceptEncoding);

    if (contentEncoding == null) {
      LOGGER.trace("No Compression: Accept encoding is : {}", acceptEncoding);
      return response;
    }

    String requestURI = httpRequest.getRequestURI();
    if (!isURLAccepted(requestURI)) {
      LOGGER.trace("No Compression: For path: ", requestURI);
      return response;
    }
    if (!isQueryStringAccepted(httpRequest.getQueryString())) {
      LOGGER.trace("No Compression: For Query String: ", httpRequest.getQueryString());
      return response;
    }
    String userAgent = httpRequest.getHeader(Constants.HTTP_USER_AGENT_HEADER);
    if (!isUserAgentAccepted(userAgent)) {
      LOGGER.trace("No Compression: For User-Agent: {}", userAgent);
      return response;
    }

    EncodedStreamsFactory encodedStreamsFactory =
        EncodedStreamsFactory.getFactoryForContentEncoding(contentEncoding);

    LOGGER.debug("Compressing response: content encoding : {}", contentEncoding);

    return new CompressedHttpServletResponseWrapper(
        httpResponse, encodedStreamsFactory, contentEncoding, compressionThreshold, this);
  }