@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2HeadersFrame){ final Http2HeadersFrame requestHeaders = (Http2HeadersFrame) msg; final SocketChannel channel = (SocketChannel) ctx.channel() .parent(); final Http2Headers headers = requestHeaders.headers(); accessLog = new AccessLog() .address(channel.remoteAddress().getHostString()) .port(channel.localAddress().getPort()) .method(headers.method()) .uri(headers.path()) .protocol(H2_PROTOCOL_NAME); } super.channelRead(ctx, msg); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { boolean lastContent = false; if (msg instanceof Http2HeadersFrame) { final Http2HeadersFrame responseHeaders = (Http2HeadersFrame) msg; final Http2Headers headers = responseHeaders.headers(); lastContent = responseHeaders.isEndStream(); accessLog.status(headers.status()) .chunked(true); } if (msg instanceof Http2DataFrame) { final Http2DataFrame data = (Http2DataFrame) msg; lastContent = data.isEndStream(); accessLog.increaseContentLength(data.content().readableBytes()); } if (lastContent) { ctx.write(msg, promise) .addListener(future -> { if (future.isSuccess()) { accessLog.log(); } }); return; } ctx.write(msg, promise); } }
void log() { if (log.isInfoEnabled()) { log.info(COMMON_LOG_FORMAT, address, user, zonedDateTime, method, uri, protocol, status, (contentLength > -1 ? contentLength : MISSING), port, duration()); } } }
accessLog.status(status.codeAsText()) .chunked(chunked); if (!chunked) { accessLog.contentLength(HttpUtil.getContentLength(response, -1)); accessLog.increaseContentLength(((LastHttpContent) msg).content().readableBytes()); ctx.write(msg, promise) .addListener(future -> { if (future.isSuccess()) { accessLog.log(); accessLog.increaseContentLength(((ByteBuf) msg).readableBytes()); accessLog.increaseContentLength(((ByteBufHolder) msg).content().readableBytes());
void log() { if (log.isInfoEnabled()) { log.info(COMMON_LOG_FORMAT, address, user, zonedDateTime, method, uri, protocol, status, (contentLength > -1 ? contentLength : MISSING), port, duration()); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { final HttpRequest request = (HttpRequest) msg; final SocketChannel channel = (SocketChannel) ctx.channel(); accessLog = new AccessLog() .address(channel.remoteAddress().getHostString()) .port(channel.localAddress().getPort()) .method(request.method().name()) .uri(request.uri()) .protocol(request.protocolVersion().text()); } super.channelRead(ctx, msg); }
accessLog.status(status.codeAsText()) .chunked(chunked); if (!chunked) { accessLog.contentLength(HttpUtil.getContentLength(response, -1)); accessLog.increaseContentLength(((LastHttpContent) msg).content().readableBytes()); ctx.write(msg, promise) .addListener(future -> { if (future.isSuccess()) { accessLog.log(); accessLog.increaseContentLength(((ByteBuf) msg).readableBytes()); accessLog.increaseContentLength(((ByteBufHolder) msg).content().readableBytes());
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { final HttpRequest request = (HttpRequest) msg; final SocketChannel channel = (SocketChannel) ctx.channel(); accessLog = new AccessLog() .address(channel.remoteAddress().getHostString()) .port(channel.localAddress().getPort()) .method(request.method().name()) .uri(request.uri()) .protocol(request.protocolVersion().text()); } super.channelRead(ctx, msg); }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { boolean lastContent = false; if (msg instanceof Http2HeadersFrame) { final Http2HeadersFrame responseHeaders = (Http2HeadersFrame) msg; final Http2Headers headers = responseHeaders.headers(); lastContent = responseHeaders.isEndStream(); accessLog.status(headers.status()) .chunked(true); } if (msg instanceof Http2DataFrame) { final Http2DataFrame data = (Http2DataFrame) msg; lastContent = data.isEndStream(); accessLog.increaseContentLength(data.content().readableBytes()); } if (lastContent) { ctx.write(msg, promise) .addListener(future -> { if (future.isSuccess()) { accessLog.log(); } }); return; } ctx.write(msg, promise); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof Http2HeadersFrame){ final Http2HeadersFrame requestHeaders = (Http2HeadersFrame) msg; final SocketChannel channel = (SocketChannel) ctx.channel() .parent(); final Http2Headers headers = requestHeaders.headers(); accessLog = new AccessLog() .address(channel.remoteAddress().getHostString()) .port(channel.localAddress().getPort()) .method(headers.method()) .uri(headers.path()) .protocol(H2_PROTOCOL_NAME); } super.channelRead(ctx, msg); }