@Test public void encodeHttpRequestChunked() throws Exception { ProtocolCodecSessionEx session = new ProtocolCodecSessionEx(); IoBufferAllocatorEx<?> allocator = session.getBufferAllocator(); ProtocolEncoder encoder = new HttpRequestEncoder(allocator); ProtocolEncoderOutput encoderOut = session.getEncoderOutput(); HttpRequestMessage httpRequest = new HttpRequestMessage(); httpRequest.setMethod(HttpMethod.POST); httpRequest.setRequestURI(URI.create("/sse")); httpRequest.setVersion(HttpVersion.HTTP_1_1); httpRequest.setHeader("Transfer-Encoding", "chunked"); IoBufferEx data = allocator.wrap(ByteBuffer.wrap("Hello, world".getBytes())); httpRequest.setContent(new HttpContentMessage(data, false, true, false)); encoder.encode(session, httpRequest, encoderOut); encoderOut.mergeAll(); IoBuffer buf = (IoBuffer)session.getEncoderOutputQueue().poll(); assertEquals("POST /sse HTTP/1.1\r\n" + "Transfer-Encoding: chunked\r\n" + "\r\n" + "c\r\n" + "Hello, world\r\n", buf.getString(Charset.forName("UTF-8").newDecoder())); }
@Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case REQUEST: HttpRequestMessage httpRequest = (HttpRequestMessage)httpMessage; encodeRequest(session, httpRequest, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } }
HttpRequestEncoder extends HttpMessageEncoder<HttpRequestMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case REQUEST: HttpRequestMessage httpRequest = (HttpRequestMessage)httpMessage; encodeRequest(session, httpRequest, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } }
HttpRequestEncoder extends HttpMessageEncoder<HttpRequestMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case REQUEST: HttpRequestMessage httpRequest = (HttpRequestMessage)httpMessage; encodeRequest(session, httpRequest, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpRequestEncoder(IoBufferAllocatorEx<?> allocator);  HttpRequestEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator); }
HttpRequestEncoder extends HttpMessageEncoder<HttpRequestMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case REQUEST: HttpRequestMessage httpRequest = (HttpRequestMessage)httpMessage; encodeRequest(session, httpRequest, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpRequestEncoder(IoBufferAllocatorEx<?> allocator);  HttpRequestEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator);  }
HttpRequestEncoder extends HttpMessageEncoder<HttpRequestMessage> { @Override protected void encode(IoSessionEx session, HttpMessage httpMessage, ProtocolEncoderOutput out) throws Exception { switch (httpMessage.getKind()) { case CONTENT: HttpContentMessage httpContent = (HttpContentMessage)httpMessage; encodeContent(session, httpContent, out); break; case REQUEST: HttpRequestMessage httpRequest = (HttpRequestMessage)httpMessage; encodeRequest(session, httpRequest, out); break; default: throw new ProtocolEncoderException("Unexpected HTTP message kind: " + httpMessage.getKind()); } } HttpRequestEncoder(IoBufferAllocatorEx<?> allocator);  HttpRequestEncoder(CachingMessageEncoder cachingEncoder, IoBufferAllocatorEx<?> allocator);   }