use of io.netty.buffer.ByteBufHolder in project reactor-netty by reactor.
the class AccessLogHandlerH1 method write.
@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
if (msg instanceof HttpResponse) {
final HttpResponse response = (HttpResponse) msg;
final HttpResponseStatus status = response.status();
if (status.equals(HttpResponseStatus.CONTINUE)) {
// "FutureReturnValueIgnored" this is deliberate
ctx.write(msg, promise);
return;
}
final boolean chunked = HttpUtil.isTransferEncodingChunked(response);
accessLogArgProvider.response(response).chunked(chunked);
if (!chunked) {
accessLogArgProvider.contentLength(HttpUtil.getContentLength(response, -1));
}
ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
if (ops instanceof HttpInfos) {
accessLogArgProvider.cookies(((HttpInfos) ops).cookies());
}
}
if (msg instanceof LastHttpContent) {
accessLogArgProvider.increaseContentLength(((LastHttpContent) msg).content().readableBytes());
ctx.write(msg, promise.unvoid()).addListener(future -> {
if (future.isSuccess()) {
AccessLog log = accessLog.apply(accessLogArgProvider);
if (log != null) {
log.log();
}
accessLogArgProvider.clear();
}
});
return;
}
if (msg instanceof ByteBuf) {
accessLogArgProvider.increaseContentLength(((ByteBuf) msg).readableBytes());
}
if (msg instanceof ByteBufHolder) {
accessLogArgProvider.increaseContentLength(((ByteBufHolder) msg).content().readableBytes());
}
// "FutureReturnValueIgnored" this is deliberate
ctx.write(msg, promise);
}
Aggregations