Only increment the counter if the encode did not fail. See #256

This commit is contained in:
norman 2012-04-12 10:55:18 +02:00
parent 5ed04c3ada
commit d363f73fd8

View File

@ -95,21 +95,22 @@ public class HttpClientCodec implements ChannelUpstreamHandler,
@Override @Override
protected Object encode(ChannelHandlerContext ctx, Channel channel, protected Object encode(ChannelHandlerContext ctx, Channel channel,
Object msg) throws Exception { Object msg) throws Exception {
if (msg instanceof HttpRequest) { if (msg instanceof HttpRequest && !done) {
if (!done) {
queue.offer(((HttpRequest) msg).getMethod()); queue.offer(((HttpRequest) msg).getMethod());
} }
Object obj = super.encode(ctx, channel, msg);
// check if the request is chunked if so do not increment // check if the request is chunked if so do not increment
if (!((HttpRequest) msg).isChunked()) { if (msg instanceof HttpRequest && !((HttpRequest) msg).isChunked()) {
requestResponseCounter.incrementAndGet(); requestResponseCounter.incrementAndGet();
}
} else if (msg instanceof HttpChunk && ((HttpChunk) msg).isLast()) { } else if (msg instanceof HttpChunk && ((HttpChunk) msg).isLast()) {
// increment as its the last chunk // increment as its the last chunk
requestResponseCounter.incrementAndGet(); requestResponseCounter.incrementAndGet();
} }
return super.encode(ctx, channel, msg);
return obj;
} }
} }