public static OutputStream checkAndWrap(HttpServletRequest httpRequest,
                                            HttpServletResponse httpResponse,
                                            boolean requireWantsHeader) throws
                                                                        IOException {
        OutputStream responseStream = httpResponse.getOutputStream();

        // GZIP Support handled here. First we must ensure that we want to use gzip, and that the client supports gzip
        boolean acceptsGzip = Collections.list(httpRequest.getHeaders(ACCEPT_ENCODING)).stream().anyMatch(STRING_MATCH);
        boolean wantGzip = httpResponse.getHeaders(CONTENT_ENCODING).contains(GZIP);

        if (acceptsGzip) {
            if (!requireWantsHeader || wantGzip) {
                responseStream = new GZIPOutputStream(responseStream, true);
                addContentEncodingHeaderIfMissing(httpResponse, wantGzip);
            }
        }

        return responseStream;
    }
Checks if the HTTP request/response accepts and wants GZIP and i that case wraps the response output stream in a
{@link java.util.zip.GZIPOutputStream}.

@param httpRequest        the HTTP servlet request.
@param httpResponse       the HTTP servlet response.
@param requireWantsHeader if wants header is required
@return if accepted and wanted a {@link java.util.zip.GZIPOutputStream} otherwise the unchanged response
output stream.
@throws IOException in case of IO error.
src/main/java/spark/utils/GzipUtils.java