Quarkus: GZip filter doesn't work

Created on 29 May 2020  路  10Comments  路  Source: quarkusio/quarkus

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

kinbug

Most helpful comment

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();
    }
}

All 10 comments

Something tells me that the following line is wrong:

https://github.com/resteasy/Resteasy/blob/master/resteasy-core/src/main/java/org/jboss/resteasy/plugins/interceptors/GZIPEncodingInterceptor.java#L78

It should be testing if Accept-Encoding contains gzip instead

I would like to work on that.

I think this is a RESTEasy bug rather than a Quarkus one.

I haven't got much time to work on it, but while debugging on a sample project, headers where looking ok on the quarkus side.

/cc @asoldano

@liweinan, can you check this please?

We had someone else report this as well. @liweinan were you able to look into this one?

@gastaldi agreed. as the standard i believe is application/gzip and not just gzip.

I am hitting this as well or at least something similar when trying to return compressed JSON. I stepped through the GZIPEncodingInterceptor code and if you add the GZIP annotation to the rest method it finds "gzip" under the Content-encoding, but still always returns json instead of encoded. I had to write my own interceptor to accomplish what I wanted. I only tested on quarkus 1.7.5.Final though and not the latest yet.

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();
    }
}
Was this page helpful?
0 / 5 - 0 ratings