use of reactor.netty.http.HttpInfos in project reactor-netty by reactor.
the class AccessLogHandlerH2 method write.
@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
boolean lastContent = false;
if (msg instanceof Http2HeadersFrame) {
final Http2HeadersFrame responseHeaders = (Http2HeadersFrame) msg;
lastContent = responseHeaders.isEndStream();
accessLogArgProvider.responseHeaders(responseHeaders).chunked(true);
ChannelOperations<?, ?> ops = ChannelOperations.get(ctx.channel());
if (ops instanceof HttpInfos) {
accessLogArgProvider.cookies(((HttpInfos) ops).cookies());
}
}
if (msg instanceof Http2DataFrame) {
final Http2DataFrame data = (Http2DataFrame) msg;
lastContent = data.isEndStream();
accessLogArgProvider.increaseContentLength(data.content().readableBytes());
}
if (lastContent) {
ctx.write(msg, promise.unvoid()).addListener(future -> {
if (future.isSuccess()) {
AccessLog log = accessLog.apply(accessLogArgProvider);
if (log != null) {
log.log();
}
accessLogArgProvider.clear();
}
});
return;
}
// "FutureReturnValueIgnored" this is deliberate
ctx.write(msg, promise);
}
use of reactor.netty.http.HttpInfos 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