Source:
public void channelRead(ChannelHandlerContext ctx, Object obj) throws Exception { logger.trace("Reading on channel {}", ctx.channel()); long startTimeInMs = -1; nettyMetrics.healthCheckRequestRate.mark(); boolean forwardObj = false; if (obj instanceof HttpRequest) { if (request == null && ((HttpRequest) obj).getUri().equals(healthCheckUri)) { logger.trace("Handling health check request while in state " + restServerState.isServiceUp()); startTimeInMs = System.currentTimeMillis(); request = (HttpRequest) obj; if (restServerState.isServiceUp()) { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(goodBytes)); HttpHeaders.setKeepAlive(response, HttpHeaders.isKeepAlive(request)); HttpHeaders.setContentLength(response, goodBytes.length); } else { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.SERVICE_UNAVAILABLE, Unpooled.wrappedBuffer(badBytes)); HttpHeaders.setKeepAlive(response, false); HttpHeaders.setContentLength(response, badBytes.length); } } else { forwardObj = true; } } if (obj instanceof LastHttpContent) { if (response != null) { ChannelFuture future = ctx.writeAndFlush(response); if (!HttpHeaders.isKeepAlive(response)) { future.addListener(ChannelFutureListener.CLOSE); } request = null; response = null; nettyMetrics.healthCheckRequestProcessingTimeInMs.update(System.currentTimeMillis() - startTimeInMs); } else { forwardObj = true; } } else if (request == null) { forwardObj = true; } if (forwardObj) { super.channelRead(ctx, obj); } else { ReferenceCountUtil.release(obj); } }

Target:
public void channelRead(ChannelHandlerContext ctx, Object obj) throws Exception { logger.trace("Reading on channel {}", ctx.channel()); boolean forwardObj = false; if (obj instanceof HttpRequest) { if (request == null && ((HttpRequest) obj).getUri().equals(healthCheckUri)) { nettyMetrics.healthCheckRequestRate.mark(); startTimeInMs = System.currentTimeMillis(); logger.trace("Handling health check request while in state " + restServerState.isServiceUp()); request = (HttpRequest) obj; if (restServerState.isServiceUp()) { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, Unpooled.wrappedBuffer(goodBytes)); HttpHeaders.setKeepAlive(response, HttpHeaders.isKeepAlive(request)); HttpHeaders.setContentLength(response, goodBytes.length); } else { response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.SERVICE_UNAVAILABLE, Unpooled.wrappedBuffer(badBytes)); HttpHeaders.setKeepAlive(response, false); HttpHeaders.setContentLength(response, badBytes.length); } nettyMetrics.healthCheckRequestProcessingTimeInMs.update(System.currentTimeMillis() - startTimeInMs); } else { forwardObj = true; } } if (obj instanceof LastHttpContent) { if (response != null) { ChannelFuture future = ctx.writeAndFlush(response); if (!HttpHeaders.isKeepAlive(response)) { future.addListener(ChannelFutureListener.CLOSE); } request = null; response = null; nettyMetrics.healthCheckRequestRoundTripTimeInMs.update(System.currentTimeMillis() - startTimeInMs); } else { forwardObj = true; } } else if (request == null) { forwardObj = true; } if (forwardObj) { super.channelRead(ctx, obj); } else { ReferenceCountUtil.release(obj); } }