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:
quarkus.resteasy.gzip.enabled=true to application.propertieshttp localhost:8080/hello Content-Encoding:gzip Accept-Encoding:gzipConfiguration
quarkus.resteasy.gzip.enabled=true
Environment (please complete the following information):
uname -a or ver: Fedora 32java -version: OpenJDK 11mvnw --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
Something tells me that the following line is wrong:
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();
}
}
Most helpful comment
As a temporary workaround I'm using the following code since June: