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

            /*
             * We have to do a bit more work with gzip versus deflate, since
             * Gzip doesn't appear to have an equivalent to DeflaterInputStream in
             * the JDK.
             *
             * UPDATE: DeflaterInputStream is Java 6 anyway, so we have to do a bit
             * of work there too!
             */
            final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            final OutputStream out = new GZIPOutputStream(bytes);

            final ByteArrayInputStream uncompressed = new ByteArrayInputStream(
                    entityText.getBytes(StandardCharsets.UTF_8));

            final byte[] buf = new byte[60];

            int n;
            while ((n = uncompressed.read(buf)) != -1) {
                out.write(buf, 0, n);
            }

            out.close();

            final byte[] arr = bytes.toByteArray();
            response.setEntity(new InputStreamEntity(new ByteArrayInputStream(arr),
                    arr.length, null));

            return;
        }
            }
         };
    }
Returns an {@link HttpRequestHandler} implementation that will attempt to provide a gzip
Content-Encoding.

@param entityText
           the non-null String entity to be returned by the server
@return a non-null {@link HttpRequestHandler}
httpclient5-testing/src/test/java/org/apache/hc/client5/testing/sync/TestContentCodings.java