/**
* 响应HTTP的请求
*
* @param ctx ChannelHandlerContext
* @param req FullHttpRequest
* @param jsonStr String
*/
private void sendResponse(ChannelHandlerContext ctx, FullHttpRequest req, String jsonStr) {
boolean keepAlive = HttpUtil.isKeepAlive(req);
byte[] jsonByteByte = jsonStr.getBytes();
FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(jsonByteByte));
response.headers().set(CONTENT_TYPE, APPLICATION_JSON);
response.headers().setInt(CONTENT_LENGTH, response.content().readableBytes());
if (!keepAlive) {
ctx.write(response).addListener(ChannelFutureListener.CLOSE);
} else {
response.headers().set(CONNECTION, KEEP_ALIVE);
ctx.write(response);
}
}
HttpServerInboundHandler.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:ace
作者:
评论列表
文章目录