Search in sources :

Example 1 with HttpInfos

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);
}
Also used : Http2DataFrame(io.netty.handler.codec.http2.Http2DataFrame) Http2HeadersFrame(io.netty.handler.codec.http2.Http2HeadersFrame) HttpInfos(reactor.netty.http.HttpInfos)

Example 2 with HttpInfos

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);
}
Also used : HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) HttpResponse(io.netty.handler.codec.http.HttpResponse) ByteBufHolder(io.netty.buffer.ByteBufHolder) HttpInfos(reactor.netty.http.HttpInfos) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) ByteBuf(io.netty.buffer.ByteBuf)

Aggregations

HttpInfos (reactor.netty.http.HttpInfos)2 ByteBuf (io.netty.buffer.ByteBuf)1 ByteBufHolder (io.netty.buffer.ByteBufHolder)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 HttpResponseStatus (io.netty.handler.codec.http.HttpResponseStatus)1 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)1 Http2DataFrame (io.netty.handler.codec.http2.Http2DataFrame)1 Http2HeadersFrame (io.netty.handler.codec.http2.Http2HeadersFrame)1