@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;

        // Check the headers to see if response is already gzipped.
        final Headers respHeaders = response.getHeaders();
        boolean isResponseCompressed = HttpUtils.isCompressed(respHeaders);

        // Decide what to do.;
        final boolean shouldGzip = isGzippableContentType(response)
                && isGzipRequested
                && !isResponseCompressed
                && isRightSizeForGzip(response);
        if (shouldGzip) {
            response.getContext().set(CommonContextKeys.GZIPPER, getGzipper());
        }
        return shouldGzip;
    }
@Test
    void prepareResponseBody_alreadyZipped() throws Exception {
        originalRequestHeaders.set("Accept-Encoding", "gzip,deflate");

        byte[] originBody = "blah".getBytes();
        response.getHeaders().set("Content-Length", Integer.toString(originBody.length));
        response.getHeaders().set("Content-Type", "application/json");
        response.getHeaders().set("Content-Encoding", "gzip");
        response.setHasBody(true);
        assertFalse(filter.shouldFilter(response));
    }