quarkus: GZip filter doesn't work

Describe the bug I followed the steps in https://quarkus.io/guides/rest-json#gzip-support but the filter doesn’t seem to be activated.

Expected behavior Content will be compressed as GZIP

Actual behavior No GZIP compression

To Reproduce Steps to reproduce the behavior:

  1. Create any endpoint with code.quarkus.io
  2. Add quarkus.resteasy.gzip.enabled=true to application.properties
  3. Run http localhost:8080/hello Content-Encoding:gzip Accept-Encoding:gzip

Configuration

quarkus.resteasy.gzip.enabled=true

Environment (please complete the following information):

  • Output of uname -a or ver: Fedora 32
  • Output of java -version: OpenJDK 11
  • GraalVM version (if different from Java):
  • Quarkus version or git rev: 1.5.0.Final
  • Build tool (ie. output of mvnw --version or gradlew --version): Maven 3.6.3

Additional context

It looks like the Content-Encoding and Accept-Encoding headers are not propagated to the internal Vert.x Request, thus making org.jboss.resteasy.plugins.interceptors.GZIPEncodingInterceptor ignore the request to GZIP the output

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 3
  • Comments: 38 (28 by maintainers)

Commits related to this issue

Most upvoted comments

Hello everyone. First of all: +1 for this topic. The workaround from @dfa1 does not work for me, the interceptor methods are called in a wrong Order (aroundWriteTo first), which is kind of confusing to me…

Nevertheless I rewrote a workaround which is working for me (even shorter):

@Provider
public class GzipSupport  implements ContainerResponseFilter {
    @Override
    public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
            throws IOException {
        String encoding = requestContext.getHeaderString(HttpHeaders.ACCEPT_ENCODING);
        if(encoding != null && encoding.contains("gzip")) {
            responseContext.getHeaders().put(HttpHeaders.CONTENT_ENCODING, Arrays.asList("gzip"));
            OutputStream outputStream = responseContext.getEntityStream();
            responseContext.setEntityStream(new GZIPOutputStream(outputStream));
        }
    }
}

As a temporary workaround I’m using the following code since June:

/**
 * Custom gzip support, workaround for https://github.com/quarkusio/quarkus/issues/9671
 *
 * NB: must be deleted when quarkus will have proper gzip support.
 */
@Provider
public class GzipSupport implements ReaderInterceptor, WriterInterceptor {

    public static final String COMPRESS_RESPONSE = "__COMPRESS_RESPONSE__";

    @Override
    public Object aroundReadFrom(ReaderInterceptorContext context) throws IOException {
        MultivaluedMap<String, String> headers = context.getHeaders();
        String wantedEncoding = headers.getFirst(HttpHeaders.ACCEPT_ENCODING);
        if (wantedEncoding != null && wantedEncoding.contains("gzip")) {
            context.setProperty(COMPRESS_RESPONSE, true);
        }
        return context.proceed();
    }

    @Override
    public void aroundWriteTo(WriterInterceptorContext context) throws IOException {
        if (Boolean.TRUE.equals(context.getProperty(COMPRESS_RESPONSE))) {
            MultivaluedMap<String, Object> headers = context.getHeaders();
            headers.add(HttpHeaders.CONTENT_ENCODING, "gzip");
            OutputStream outputStream = context.getOutputStream();
            context.setOutputStream(new GZIPOutputStream(outputStream));
        }
        context.proceed();
    }
}

@geoand do we have a GZip filter in RESTEasy Reactive?

@StFS Attached PR incoming. This should fix a lot of config issues for Resteasy Standalone. You’ll configure via application.properties

@jessequinn @gastaldi That line in the resteasy interceptor looks correct

     Object encoding = context.getHeaders().getFirst(HttpHeaders.CONTENT_ENCODING);

In this case the headers being checked are response headers not request headers. When accepting gzip from a request the server should respond with the headers Content-Encoding: gzip

@liweinan, can you check this please?

I would like to work on that.