From d363f73fd831be950a2ba2e39b7f51df1cee0fea Mon Sep 17 00:00:00 2001 From: norman Date: Thu, 12 Apr 2012 10:55:18 +0200 Subject: [PATCH] Only increment the counter if the encode did not fail. See #256 --- .../handler/codec/http/HttpClientCodec.java | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 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 ba28c41ab7..10404e8c16 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 @@ -95,21 +95,22 @@ public class HttpClientCodec implements ChannelUpstreamHandler, @Override protected Object encode(ChannelHandlerContext ctx, Channel channel, Object msg) throws Exception { - if (msg instanceof HttpRequest) { - if (!done) { - queue.offer(((HttpRequest) msg).getMethod()); - } - - // check if the request is chunked if so do not increment - if (!((HttpRequest) msg).isChunked()) { - requestResponseCounter.incrementAndGet(); - } + if (msg instanceof HttpRequest && !done) { + queue.offer(((HttpRequest) msg).getMethod()); + } + + Object obj = super.encode(ctx, channel, msg); + + // check if the request is chunked if so do not increment + if (msg instanceof HttpRequest && !((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); + + return obj; + } }