Example #1
0
 @Override
 public final boolean trySend(WebDataMessage message) {
   if (!message.isBinary()) ctx.writeAndFlush(new TextWebSocketFrame(message.getStringBody()));
   else
     ctx.writeAndFlush(
         new BinaryWebSocketFrame(Unpooled.wrappedBuffer(message.getByteBufferBody())));
   return true;
 }
Example #2
0
 @Override
 public final boolean trySend(WebDataMessage res) {
   final ByteBuf buf;
   final String stringBody = res.getStringBody();
   if (stringBody != null) {
     byte[] bs = stringBody.getBytes(encoding);
     buf = Unpooled.wrappedBuffer(bs);
   } else {
     buf = Unpooled.wrappedBuffer(res.getByteBufferBody());
   }
   ctx.writeAndFlush(buf);
   return true;
 }
Example #3
0
  private static void writeHttpResponse(
      ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res, Boolean close) {
    if (!omitDateHeader && !res.headers().contains(DefaultHttpHeaders.Names.DATE))
      DefaultHttpHeaders.addDateHeader(res, DefaultHttpHeaders.Names.DATE, new Date());

    // Send the response and close the connection if necessary.
    if (!HttpHeaders.isKeepAlive(req) || res.getStatus().code() != 200 || close == null || close) {
      res.headers().set(CONNECTION, HttpHeaders.Values.CLOSE);
      ctx.writeAndFlush(res).addListener(ChannelFutureListener.CLOSE);
    } else {
      res.headers().set(CONNECTION, HttpHeaders.Values.KEEP_ALIVE);
      write(ctx, res);
    }
  }
Example #4
0
 private static ChannelFuture write(ChannelHandlerContext ctx, Object res) {
   return ctx.writeAndFlush(res);
   // : ctx.write(res);
 }