Skip to content

Commit

Permalink
Introduce ChunkedZipResponse (#109820)
Browse files Browse the repository at this point in the history
Adds a utility for implementing REST APIs which construct a streaming
(i.e. pretty-much-constant-memory) `.zip` file response as a (pausable)
sequence of `ChunkedRestResponseBodyPart` instances, where each entry in
the `.zip` file is itself a (pausable) sequence of
`ChunkedRestResponseBodyPart` instances.

Relates #104851
  • Loading branch information
DaveCTurner authored and mhl-b committed Aug 8, 2024
1 parent bfb8e7f commit 4e596d0
Show file tree
Hide file tree
Showing 3 changed files with 1,066 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.elasticsearch.http.HttpServerTransport;
import org.elasticsearch.http.netty4.internal.HttpHeadersAuthenticatorUtils;
import org.elasticsearch.http.netty4.internal.HttpValidator;
import org.elasticsearch.rest.ChunkedZipResponse;
import org.elasticsearch.telemetry.tracing.Tracer;
import org.elasticsearch.threadpool.ThreadPool;
import org.elasticsearch.transport.netty4.AcceptChannelHandler;
Expand Down Expand Up @@ -382,7 +383,16 @@ protected boolean isContentAlwaysEmpty(HttpResponse msg) {
})
.addLast("aggregator", aggregator);
if (handlingSettings.compression()) {
ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(handlingSettings.compressionLevel()));
ch.pipeline().addLast("encoder_compress", new HttpContentCompressor(handlingSettings.compressionLevel()) {
@Override
protected Result beginEncode(HttpResponse httpResponse, String acceptEncoding) throws Exception {
if (ChunkedZipResponse.ZIP_CONTENT_TYPE.equals(httpResponse.headers().get("content-type"))) {
return null;
} else {
return super.beginEncode(httpResponse, acceptEncoding);
}
}
});
}
ch.pipeline()
.addLast(
Expand Down
Loading

0 comments on commit 4e596d0

Please sign in to comment.