|
16 | 16 | import static com.google.common.base.Preconditions.checkState; |
17 | 17 |
|
18 | 18 | import com.google.auth.Credentials; |
| 19 | +import com.google.common.base.Joiner; |
19 | 20 | import com.google.common.collect.ImmutableList; |
| 21 | +import com.google.common.collect.Lists; |
20 | 22 | import io.netty.buffer.ByteBuf; |
21 | 23 | import io.netty.channel.ChannelHandlerContext; |
22 | 24 | import io.netty.channel.ChannelPromise; |
| 25 | +import io.netty.handler.codec.compression.Zstd; |
23 | 26 | import io.netty.handler.codec.http.DefaultFullHttpRequest; |
24 | 27 | import io.netty.handler.codec.http.HttpContent; |
25 | 28 | import io.netty.handler.codec.http.HttpHeaderNames; |
|
33 | 36 | import io.netty.handler.codec.http.HttpVersion; |
34 | 37 | import io.netty.handler.codec.http.LastHttpContent; |
35 | 38 | import io.netty.handler.timeout.ReadTimeoutException; |
| 39 | +import io.netty.util.AsciiString; |
36 | 40 | import io.netty.util.internal.StringUtil; |
37 | 41 | import java.io.ByteArrayOutputStream; |
38 | 42 | import java.io.IOException; |
39 | 43 | import java.io.OutputStream; |
| 44 | +import java.util.ArrayList; |
40 | 45 | import java.util.Map.Entry; |
41 | 46 |
|
42 | 47 | /** ChannelHandler for downloads. */ |
43 | 48 | final class HttpDownloadHandler extends AbstractHttpHandler<HttpObject> { |
44 | 49 |
|
| 50 | + private static final String ACCEPT_ENCODING = getAcceptEncoding(); |
| 51 | + |
45 | 52 | private OutputStream out; |
46 | 53 | private boolean keepAlive = HttpVersion.HTTP_1_1.isKeepAliveDefault(); |
47 | 54 | private boolean downloadSucceeded; |
@@ -180,7 +187,7 @@ private HttpRequest buildRequest(String path, String host) { |
180 | 187 | httpRequest.headers().set(HttpHeaderNames.HOST, host); |
181 | 188 | httpRequest.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); |
182 | 189 | httpRequest.headers().set(HttpHeaderNames.ACCEPT, "*/*"); |
183 | | - httpRequest.headers().set(HttpHeaderNames.ACCEPT_ENCODING, HttpHeaderValues.GZIP); |
| 190 | + httpRequest.headers().set(HttpHeaderNames.ACCEPT_ENCODING, ACCEPT_ENCODING); |
184 | 191 | return httpRequest; |
185 | 192 | } |
186 | 193 |
|
@@ -232,4 +239,14 @@ private void reset(ChannelHandlerContext ctx) { |
232 | 239 | response = null; |
233 | 240 | } |
234 | 241 | } |
| 242 | + |
| 243 | + private static String getAcceptEncoding() { |
| 244 | + ArrayList<AsciiString> acceptEncoding = |
| 245 | + Lists.newArrayList( |
| 246 | + HttpHeaderValues.GZIP, HttpHeaderValues.DEFLATE, HttpHeaderValues.SNAPPY); |
| 247 | + if (Zstd.isAvailable()) { |
| 248 | + acceptEncoding.add(HttpHeaderValues.ZSTD); |
| 249 | + } |
| 250 | + return Joiner.on(",").join(acceptEncoding); |
| 251 | + } |
235 | 252 | } |
0 commit comments