use of info.xiancloud.nettyhttpserver.http.bean.ResponseWrapper in project xian by happyyangyuan.
the class HttpResponseBuilder method write.
@Override
public void write(ChannelHandlerContext ctx, Object responseMsg, ChannelPromise promise) throws Exception {
ResponseWrapper responseWrapper = (ResponseWrapper) responseMsg;
FullHttpResponse httpResponse = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.copiedBuffer(responseWrapper.getResPayload().toString(), Config.defaultUtf8()));
httpResponse.headers().set(CONTENT_TYPE, contentType(responseWrapper));
httpResponse.headers().set(CONTENT_LENGTH, httpResponse.content().readableBytes());
LOG.debug("我们不适用http1.1协议默认的keep-alive = true以及请求的header中的keep-alive来决定连接是否keep-alvie而是使用自定义的header: LONG_CONNECTION");
Boolean keepAlive = ctx.channel().attr(ClearingHandler.LONG_CONNECTION).get();
if (keepAlive) {
httpResponse.headers().set(CONNECTION, HttpHeaderValues.KEEP_ALIVE);
} else {
httpResponse.headers().set(CONNECTION, HttpHeaderValues.CLOSE);
}
/*LOG.info("<<<<<<<<<<<< netty 返回 HttpResponse: \r\n" + httpResponse);*/
super.write(ctx, httpResponse, promise);
}
use of info.xiancloud.nettyhttpserver.http.bean.ResponseWrapper in project xian by happyyangyuan.
the class ResReceived method write.
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
ResponseWrapper response = (ResponseWrapper) msg;
MsgIdHolder.set(response.getRequest().getMsgId());
/*LOG.debug("<<<<<<<<<<<<< 收到业务层的响应:" + msg);*/
super.write(ctx, msg, promise);
}
Aggregations