@Override
    public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
        ChannelPromise closePromise = ctx.channel()
                .attr(ConnectionCloseChannelAttributes.CLOSE_AFTER_RESPONSE)
                .get();

        if (msg instanceof HttpResponse response && closePromise != null) {
            // Add header to tell client that they should close this connection.
            response.headers().set(HttpHeaderNames.CONNECTION, "close");
        }

        super.write(ctx, msg, promise);

        // Close the connection immediately after LastContent is written, rather than
        // waiting until the graceful-delay is up if this flag is set.
        if (msg instanceof LastHttpContent) {
            if (closePromise != null) {
                promise.addListener(future -> {
                    ConnectionCloseType type = ConnectionCloseType.fromChannel(ctx.channel());
                    closeChannel(ctx, type, closePromise);
                });
            }
        }
    }
User: michaels@netflix.com
Date: 2/8/17
Time: 2:03 PM
zuul-core/src/main/java/com/netflix/netty/common/Http1ConnectionCloseHandler.java