@Override public boolean shouldFilter(HttpResponseMessage response) { if (!ENABLED.get() || !response.hasBody() || response.getContext().isInBrownoutMode()) { return false; } if (response.getContext().get(CommonContextKeys.GZIPPER) != null) { return true; } // A flag on SessionContext can be set to override normal mechanism of checking if client accepts gzip.; final HttpRequestInfo request = response.getInboundRequest(); final Boolean overrideIsGzipRequested = (Boolean) response.getContext().get(CommonContextKeys.OVERRIDE_GZIP_REQUESTED); final boolean isGzipRequested = (overrideIsGzipRequested == null) ? HttpUtils.acceptsGzip(request.getHeaders()) : overrideIsGzipRequested.booleanValue(); // Check the headers to see if response is already gzipped. final Headers respHeaders = response.getHeaders(); boolean isResponseGzipped = HttpUtils.isGzipped(respHeaders); // Decide what to do.; final boolean shouldGzip = isGzippableContentType(response) && isGzipRequested && !isResponseGzipped && isRightSizeForGzip(response); if (shouldGzip) { response.getContext().set(CommonContextKeys.GZIPPER, new Gzipper()); } return shouldGzip; }
@Override public boolean shouldFilter(HttpResponseMessage response) { if (!ENABLED.get() || !response.hasBody() || response.getContext().isInBrownoutMode()) { return false; } if (response.getContext().get(CommonContextKeys.GZIPPER) != null) { return true; } // A flag on SessionContext can be set to override normal mechanism of checking if client accepts gzip.; final HttpRequestInfo request = response.getInboundRequest(); final Boolean overrideIsGzipRequested = (Boolean) response.getContext().get(CommonContextKeys.OVERRIDE_GZIP_REQUESTED); final boolean isGzipRequested = (overrideIsGzipRequested == null) ? HttpUtils.acceptsGzip(request.getHeaders()) : overrideIsGzipRequested.booleanValue(); // Check the headers to see if response is already gzipped. final Headers respHeaders = response.getHeaders(); boolean isResponseGzipped = HttpUtils.isGzipped(respHeaders); // Decide what to do.; final boolean shouldGzip = isGzippableContentType(response) && isGzipRequested && !isResponseGzipped && isRightSizeForGzip(response); if (shouldGzip) { response.getContext().set(CommonContextKeys.GZIPPER, new Gzipper()); } return shouldGzip; }
@Override public boolean shouldFilter(HttpResponseMessage response) { if (!response.hasBody() || response.getContext().isInBrownoutMode()) { return false; } if (response.getContext().get(CommonContextKeys.GZIPPER) != null) { return true; } // A flag on SessionContext can be set to override normal mechanism of checking if client accepts gzip.; final HttpRequestInfo request = response.getInboundRequest(); final Boolean overrideIsGzipRequested = (Boolean) response.getContext().get(CommonContextKeys.OVERRIDE_GZIP_REQUESTED); final boolean isGzipRequested = (overrideIsGzipRequested == null) ? HttpUtils.acceptsGzip(request.getHeaders()) : overrideIsGzipRequested.booleanValue(); // Check the headers to see if response is already gzipped. final Headers respHeaders = response.getHeaders(); boolean isResponseGzipped = HttpUtils.isGzipped(respHeaders); // Decide what to do.; final boolean shouldGzip = isGzippableContentType(response) && isGzipRequested && !isResponseGzipped && isRightSizeForGzip(response); if (shouldGzip) { response.getContext().set(CommonContextKeys.GZIPPER, new Gzipper()); } return shouldGzip; }