@Override public void handlerAdded(ChannelHandlerContext ctx) throws Exception { List<ByteBuf> payload; HttpHeaders headers = new CombinedHttpHeaders(true); headers.add(HttpHeaderNames.UPGRADE, "TLS/1.2"); headers.add(HttpHeaderNames.UPGRADE, HTTP_1_1); headers.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE); headers.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.CLOSE); headers.add(HttpHeaderNames.CONTENT_LENGTH, "0"); DefaultFullHttpResponse response = new DefaultFullHttpResponse( HTTP_1_1, UPGRADE_REQUIRED, Unpooled.EMPTY_BUFFER, headers, EmptyHttpHeaders.INSTANCE); payload = Recipes.encodeResponse(response); for (ByteBuf buffer : payload) { ctx.write(buffer.copy()); } ctx.writeAndFlush(Unpooled.EMPTY_BUFFER).addListener(ChannelFutureListener.CLOSE); } }