in tchannel-crossdock/src/main/java/com/uber/tchannel/crossdock/HTTPServer.java [55:93]
protected void channelRead0(
ChannelHandlerContext channelHandlerContext,
FullHttpRequest fullHttpRequest
) throws Exception {
logger.warn("Received {}", fullHttpRequest);
if (HttpUtil.is100ContinueExpected(fullHttpRequest)) {
channelHandlerContext.writeAndFlush(
new DefaultFullHttpResponse(
HttpVersion.HTTP_1_1,
HttpResponseStatus.CONTINUE));
}
HttpResponse response = new DefaultHttpResponse(
fullHttpRequest.protocolVersion(),
HttpResponseStatus.OK);
HttpHeaders headers = response.headers();
headers.set(CONTENT_TYPE, "text/html; charset=UTF-8");
ByteBuf responseContent = Unpooled.copiedBuffer("OK", CharsetUtil.UTF_8);
boolean keepAlive = HttpUtil.isKeepAlive(fullHttpRequest);
if (keepAlive) {
headers.set(CONTENT_LENGTH, responseContent.readableBytes());
headers.set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
}
// write response
channelHandlerContext.write(response);
channelHandlerContext.write(responseContent);
ChannelFuture future = channelHandlerContext.writeAndFlush(
LastHttpContent.EMPTY_LAST_CONTENT);
// Decide whether to close the connection or not.
if (!keepAlive) {
future.addListener(ChannelFutureListener.CLOSE);
}
}