Skip to content

Commit 57ea85a

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

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/main/java/com/ning/http/client/providers/netty/NettyAsyncHttpProviderConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ public Set<Map.Entry<String, Object>> propertiesSet() {
143143

144144
private int webSocketMaxFrameSize = 10 * 1024;
145145

146+
private boolean keepEncodingHeader = false;
147+
146148
public boolean isUseDeadLockChecker() {
147149
return useDeadLockChecker;
148150
}
@@ -295,6 +297,14 @@ public void setWebSocketMaxFrameSize(int webSocketMaxFrameSize) {
295297
this.webSocketMaxFrameSize = webSocketMaxFrameSize;
296298
}
297299

300+
public boolean isKeepEncodingHeader() {
301+
return keepEncodingHeader;
302+
}
303+
304+
public void setKeepEncodingHeader(boolean keepEncodingHeader) {
305+
this.keepEncodingHeader = keepEncodingHeader;
306+
}
307+
298308
public static interface NettyWebSocketFactory {
299309
NettyWebSocket newNettyWebSocket(Channel channel, NettyAsyncHttpProviderConfig nettyConfig);
300310
}

src/main/java/com/ning/http/client/providers/netty/channel/ChannelManager.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public void configureBootstraps(NettyRequestSender requestSender, AtomicBoolean
204204
public ChannelPipeline getPipeline() throws Exception {
205205
ChannelPipeline pipeline = pipeline();
206206
pipeline.addLast(HTTP_HANDLER, newHttpClientCodec());
207-
pipeline.addLast(INFLATER_HANDLER, new HttpContentDecompressor());
207+
pipeline.addLast(INFLATER_HANDLER, newHttpContentDecompressor());
208208
pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler());
209209
pipeline.addLast(HTTP_PROCESSOR, httpProcessor);
210210

@@ -235,7 +235,7 @@ public ChannelPipeline getPipeline() throws Exception {
235235
ChannelPipeline pipeline = pipeline();
236236
pipeline.addLast(SSL_HANDLER, new SslInitializer(ChannelManager.this));
237237
pipeline.addLast(HTTP_HANDLER, newHttpClientCodec());
238-
pipeline.addLast(INFLATER_HANDLER, new HttpContentDecompressor());
238+
pipeline.addLast(INFLATER_HANDLER, newHttpContentDecompressor());
239239
pipeline.addLast(CHUNKED_WRITER_HANDLER, new ChunkedWriteHandler());
240240
pipeline.addLast(HTTP_PROCESSOR, httpProcessor);
241241

@@ -262,6 +262,18 @@ public ChannelPipeline getPipeline() throws Exception {
262262
});
263263
}
264264

265+
private HttpContentDecompressor newHttpContentDecompressor() {
266+
if (nettyConfig.isKeepEncodingHeader())
267+
return new HttpContentDecompressor() {
268+
@Override
269+
protected String getTargetContentEncoding(String contentEncoding) throws Exception {
270+
return contentEncoding;
271+
}
272+
};
273+
else
274+
return new HttpContentDecompressor();
275+
}
276+
265277
public final void tryToOfferChannelToPool(Channel channel, boolean keepAlive, String partition) {
266278
if (channel.isConnected() && keepAlive && channel.isReadable()) {
267279
LOGGER.debug("Adding key: {} for channel {}", partition, channel);
@@ -388,14 +400,14 @@ public static SslHandler getSslHandler(ChannelPipeline pipeline) {
388400
public static boolean isSslHandlerConfigured(ChannelPipeline pipeline) {
389401
return pipeline.get(SSL_HANDLER) != null;
390402
}
391-
403+
392404
public void upgradeProtocol(ChannelPipeline pipeline, String scheme, String host, int port) throws IOException,
393405
GeneralSecurityException {
394406
if (pipeline.get(HTTP_HANDLER) != null)
395407
pipeline.remove(HTTP_HANDLER);
396408

397409
if (isSecure(scheme))
398-
if (isSslHandlerConfigured(pipeline)){
410+
if (isSslHandlerConfigured(pipeline)) {
399411
pipeline.addAfter(SSL_HANDLER, HTTP_HANDLER, newHttpClientCodec());
400412
} else {
401413
pipeline.addFirst(HTTP_HANDLER, newHttpClientCodec());
@@ -434,7 +446,8 @@ public ClientBootstrap getBootstrap(String scheme, boolean useProxy, boolean use
434446
public void upgradePipelineForWebSockets(ChannelPipeline pipeline) {
435447
pipeline.addAfter(HTTP_HANDLER, WS_ENCODER_HANDLER, new WebSocket08FrameEncoder(true));
436448
pipeline.remove(HTTP_HANDLER);
437-
pipeline.addBefore(WS_PROCESSOR, WS_DECODER_HANDLER, new WebSocket08FrameDecoder(false, false, nettyConfig.getWebSocketMaxFrameSize()));
449+
pipeline.addBefore(WS_PROCESSOR, WS_DECODER_HANDLER,
450+
new WebSocket08FrameDecoder(false, false, nettyConfig.getWebSocketMaxFrameSize()));
438451
pipeline.addAfter(WS_DECODER_HANDLER, WS_FRAME_AGGREGATOR, new WebSocketFrameAggregator(nettyConfig.getWebSocketMaxBufferSize()));
439452
}
440453

@@ -455,7 +468,7 @@ public void drainChannel(final Channel channel, final NettyResponseFuture<?> fut
455468

456469
public void flushPartition(String partitionId) {
457470
channelPool.flushPartition(partitionId);
458-
}
471+
}
459472

460473
public void flushPartitions(ChannelPoolPartitionSelector selector) {
461474
channelPool.flushPartitions(selector);

0 commit comments

Comments
 (0)