private HttpRequestHandler createDeflateEncodingRequestHandler(
            final String entityText, final boolean rfc1951) {
        return (request, response, context) -> {
            response.setEntity(new StringEntity(entityText));
            response.addHeader("Content-Type", "text/plain");
            final Iterator<HeaderElement> it = MessageSupport.iterate(request, "Accept-Encoding");
            while (it.hasNext()) {
        final HeaderElement element = it.next();
        if ("deflate".equalsIgnoreCase(element.getName())) {
            response.addHeader("Content-Encoding", "deflate");

                /* Gack. DeflaterInputStream is Java 6. */
            // response.setEntity(new InputStreamEntity(new DeflaterInputStream(new
            // ByteArrayInputStream(
            // entityText.getBytes("utf-8"))), -1));
            final byte[] uncompressed = entityText.getBytes(StandardCharsets.UTF_8);
            final Deflater compressor = new Deflater(Deflater.DEFAULT_COMPRESSION, rfc1951);
            compressor.setInput(uncompressed);
            compressor.finish();
            final byte[] output = new byte[100];
            final int compressedLength = compressor.deflate(output);
            final byte[] compressed = new byte[compressedLength];
            System.arraycopy(output, 0, compressed, 0, compressedLength);
            response.setEntity(new InputStreamEntity(
                    new ByteArrayInputStream(compressed), compressedLength, null));
            return;
        }
            }
         };
    }
Creates a new {@link HttpRequestHandler} that will attempt to provide a deflate stream
Content-Coding.

@param entityText
           the non-null String entity text to be returned by the server
@param rfc1951
           if true, then the stream returned will be a raw RFC1951 deflate stream, which
           some servers return as a result of misinterpreting the HTTP 1.1 RFC. If false,
           then it will return an RFC2616 compliant deflate encoded zlib stream.
@return a non-null {@link HttpRequestHandler}
httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java