code: private void sendAndCleanupConnection(ChannelHandlerContext ctx, FullHttpResponse response) {
          final FullHttpRequest request = this.request;
          final boolean keepAlive = HttpUtil.isKeepAlive(request);
          HttpUtil.setContentLength(response, response.content().readableBytes());
          if (!keepAlive) {
              // We're going to close the connection as soon as the response is sent,
              // so we should also make it clear for the client.
              response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE);
          } else if (request.protocolVersion().equals(HTTP_1_0)) {
              response.headers().set(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE);
          }
  
          ChannelFuture flushPromise = ctx.writeAndFlush(response);
  
          if (!keepAlive) {
              // Close the connection as soon as the response is sent.
              flushPromise.addListener(ChannelFutureListener.CLOSE);
          }
      }
docs: If Keep-Alive is disabled, attaches "Connection: close" header to the response
  and closes the connection after the response being sent.