Skip to content

Commit dcbcf67

Browse files
author
Stephane Landelle
committed
Add an option for not dropping Encoding response header, close AsyncHttpClient#723
1 parent c33be00 commit dcbcf67

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

providers/netty/src/main/java/org/asynchttpclient/providers/netty/NettyAsyncHttpProviderConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ public NettyWebSocket newNettyWebSocket(Channel channel, NettyAsyncHttpProviderC
169169

170170
private int webSocketMaxFrameSize = 10 * 1024;
171171

172+
private boolean keepEncodingHeader = false;
173+
172174
public EventLoopGroup getEventLoopGroup() {
173175
return eventLoopGroup;
174176
}
@@ -311,4 +313,12 @@ public int getWebSocketMaxFrameSize() {
311313
public void setWebSocketMaxFrameSize(int webSocketMaxFrameSize) {
312314
this.webSocketMaxFrameSize = webSocketMaxFrameSize;
313315
}
316+
317+
public boolean isKeepEncodingHeader() {
318+
return keepEncodingHeader;
319+
}
320+
321+
public void setKeepEncodingHeader(boolean keepEncodingHeader) {
322+
this.keepEncodingHeader = keepEncodingHeader;
323+
}
314324
}

providers/netty/src/main/java/org/asynchttpclient/providers/netty/channel/ChannelManager.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public void configureBootstraps(NettyRequestSender requestSender, AtomicBoolean
187187
protected void initChannel(Channel ch) throws Exception {
188188
ch.pipeline()//
189189
.addLast(HTTP_HANDLER, newHttpClientCodec())//
190-
.addLast(INFLATER_HANDLER, new HttpContentDecompressor())//
190+
.addLast(INFLATER_HANDLER, newHttpContentDecompressor())//
191191
.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())//
192192
.addLast(HTTP_PROCESSOR, httpProcessor);
193193

@@ -215,7 +215,7 @@ protected void initChannel(Channel ch) throws Exception {
215215
ch.pipeline()//
216216
.addLast(SSL_HANDLER, new SslInitializer(ChannelManager.this))//
217217
.addLast(HTTP_HANDLER, newHttpClientCodec())//
218-
.addLast(INFLATER_HANDLER, new HttpContentDecompressor())//
218+
.addLast(INFLATER_HANDLER, newHttpContentDecompressor())//
219219
.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler())//
220220
.addLast(HTTP_PROCESSOR, httpProcessor);
221221

@@ -239,6 +239,18 @@ protected void initChannel(Channel ch) throws Exception {
239239
});
240240
}
241241

242+
private HttpContentDecompressor newHttpContentDecompressor() {
243+
if (nettyConfig.isKeepEncodingHeader())
244+
return new HttpContentDecompressor() {
245+
@Override
246+
protected String getTargetContentEncoding(String contentEncoding) throws Exception {
247+
return contentEncoding;
248+
}
249+
};
250+
else
251+
return new HttpContentDecompressor();
252+
}
253+
242254
public final void tryToOfferChannelToPool(Channel channel, boolean keepAlive, String partitionId) {
243255
if (channel.isActive() && keepAlive && channel.isActive()) {
244256
LOGGER.debug("Adding key: {} for channel {}", partitionId, channel);

0 commit comments

Comments
 (0)