From 5ed04c3ada397d90f8d750175ed1d63ddc5bb86d Mon Sep 17 00:00:00 2001 From: norman Date: Thu, 12 Apr 2012 10:34:16 +0200 Subject: [PATCH] Correctly handle chunked requests/responses. See #256 --- .../netty/handler/codec/http/HttpClientCodec.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java index cd16cca75f..ba28c41ab7 100644 --- a/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java +++ b/codec-http/src/main/java/io/netty/handler/codec/http/HttpClientCodec.java @@ -99,13 +99,15 @@ public class HttpClientCodec implements ChannelUpstreamHandler, if (!done) { queue.offer(((HttpRequest) msg).getMethod()); } - requestResponseCounter.incrementAndGet(); - } else if (msg instanceof HttpChunk) { - // increment only if its the last chunk - if (((HttpChunk) msg).isLast()) { + // check if the request is chunked if so do not increment + if (!((HttpRequest) msg).isChunked()) { requestResponseCounter.incrementAndGet(); } + } else if (msg instanceof HttpChunk && ((HttpChunk) msg).isLast()) { + // increment as its the last chunk + requestResponseCounter.incrementAndGet(); + } return super.encode(ctx, channel, msg); } @@ -126,7 +128,8 @@ public class HttpClientCodec implements ChannelUpstreamHandler, Object msg = super.decode(ctx, channel, buffer, state); if (msg != null) { - if (msg instanceof HttpMessage) { + // check if its a HttpMessage and its not chunked + if (msg instanceof HttpMessage && !((HttpMessage) msg).isChunked()) { requestResponseCounter.decrementAndGet(); } else if (msg instanceof HttpChunk && ((HttpChunk) msg).isLast()) { requestResponseCounter.decrementAndGet();