Search in sources :

Example 11 with ByteBufAllocator

use of com.generallycloud.baseio.buffer.ByteBufAllocator in project baseio by generallycloud.

the class ClientHTTPProtocolEncoder method encode.

@Override
public void encode(SocketChannel channel, ChannelFuture future) throws IOException {
    ByteBufAllocator allocator = channel.getByteBufAllocator();
    HttpFuture f = (HttpFuture) future;
    ByteBuf buf = allocator.allocate(256);
    buf.put(f.getMethod().getBytes());
    buf.putByte(SPACE);
    buf.put(getRequestURI(f).getBytes());
    buf.put(PROTOCOL);
    writeHeaders(f, buf);
    List<Cookie> cookieList = f.getCookieList();
    if (cookieList != null && cookieList.size() > 0) {
        buf.put(COOKIE);
        for (Cookie c : cookieList) {
            writeBuf(buf, c.getName().getBytes());
            writeBuf(buf, COLON);
            writeBuf(buf, c.getValue().getBytes());
            writeBuf(buf, SEMICOLON);
        }
        buf.position(buf.position() - 1);
    }
    buf.put(RN);
    future.setByteBuf(buf.flip());
}
Also used : Cookie(com.generallycloud.baseio.codec.http11.future.Cookie) ByteBufAllocator(com.generallycloud.baseio.buffer.ByteBufAllocator) ByteBuf(com.generallycloud.baseio.buffer.ByteBuf) HttpFuture(com.generallycloud.baseio.codec.http11.future.HttpFuture)

Aggregations

ByteBufAllocator (com.generallycloud.baseio.buffer.ByteBufAllocator)11 ByteBuf (com.generallycloud.baseio.buffer.ByteBuf)9 UnpooledByteBufAllocator (com.generallycloud.baseio.buffer.UnpooledByteBufAllocator)3 IOException (java.io.IOException)2 PooledByteBufAllocatorManager (com.generallycloud.baseio.buffer.PooledByteBufAllocatorManager)1 CharBasedFuture (com.generallycloud.baseio.codec.charbased.future.CharBasedFuture)1 FixedLengthFuture (com.generallycloud.baseio.codec.fixedlength.future.FixedLengthFuture)1 Cookie (com.generallycloud.baseio.codec.http11.future.Cookie)1 HttpFuture (com.generallycloud.baseio.codec.http11.future.HttpFuture)1 ServerHttpFuture (com.generallycloud.baseio.codec.http11.future.ServerHttpFuture)1 WebSocketFuture (com.generallycloud.baseio.codec.http11.future.WebSocketFuture)1 Http2Frame (com.generallycloud.baseio.codec.http2.future.Http2Frame)1 Http2FrameType (com.generallycloud.baseio.codec.http2.future.Http2FrameType)1 Http2HeadersFrame (com.generallycloud.baseio.codec.http2.future.Http2HeadersFrame)1 Http2SettingsFrame (com.generallycloud.baseio.codec.http2.future.Http2SettingsFrame)1 ParamedProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ParamedProtobaseFutureImpl)1 ProtobaseFuture (com.generallycloud.baseio.codec.protobase.future.ProtobaseFuture)1 ProtobaseFutureImpl (com.generallycloud.baseio.codec.protobase.future.ProtobaseFutureImpl)1 ByteArrayBuffer (com.generallycloud.baseio.component.ByteArrayBuffer)1 NioSocketChannelContext (com.generallycloud.baseio.component.NioSocketChannelContext)1