Hi Folks,
We are in a need of streaming GZip handler as current GZipHandler does not seem to support it.
Here's what we have so far:
@Override
public Response handle(Request request) throws Exception {
Response response = httpHandler.handle(request);
if (clientAcceptsGZip(request)) {
Response gzippedResponse = response
.headers(add(VARY, ACCEPT_ENCODING))
.header(CONTENT_ENCODING, GZIP);
if (response.entity().value() instanceof StreamingOutput) {
StreamingOutput decoratedStreamingOutput = (StreamingOutput) gzippedResponse.entity().value();
return gzippedResponse.entity((StreamingOutput) streamingOutput -> {
try(GZIPOutputStream outputStream = new GZIPOutputStream(streamingOutput)) {
decoratedStreamingOutput.write(outputStream);
}
});
} else {
return gzippedResponse.entity(gzip(response.entity().toBytes()));
}
}
return response;
}
Few questions around that:
1. As we tried add support for all entity types we have noticed StreamingWriter, which uses java Writer, meant to be used with character stream. I understand convenience but given that response can be a stream of bytes, I don't think that Writer is appropriate here. Can we refactor out StreamingWriter? Is there another way to wrap GZip Stream in there.
2. Happy to keep this project-local but is this change useful enough to be a pull request or commit maybe?
3. Not that I can see but are there any other places that should be taken care of apart from handler to add GZip streaming support.
Cheers,
Al