WebSocketValidationHandler.java 文件源码

java
阅读 25 收藏 0 点赞 0 评论 0

项目:xockets.io 作者:
/**
 * Send http response.
 *
 * @param ctx the ctx
 * @param req the req
 * @param res the res
 */
private static void sendHttpResponse(ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res) {
    // Generate an error page if response getStatus code is not OK (200).
    if (res.status().code() != 200) {
        ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8);
        res.content().writeBytes(buf);
        buf.release();
        HttpUtil.setContentLength(res, res.content().readableBytes());
    }

    // Send the response and close the connection if necessary.
    ChannelFuture f = ctx.channel().writeAndFlush(res);
    if (!HttpUtil.isKeepAlive(req) || res.status().code() != 200) {
        f.addListener(ChannelFutureListener.CLOSE);
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号