use of io.netty.handler.codec.http.DefaultLastHttpContent in project ballerina by ballerina-lang.
the class MessageUtils method generateHTTPMessage.
public static HTTPTestRequest generateHTTPMessage(String path, String method, List<Header> headers, String payload) {
HTTPTestRequest carbonMessage = getHttpTestRequest(path, method);
HttpHeaders httpHeaders = carbonMessage.getHeaders();
if (headers != null) {
for (Header header : headers) {
httpHeaders.set(header.getName(), header.getValue());
}
}
if (payload != null) {
carbonMessage.addHttpContent(new DefaultLastHttpContent(Unpooled.wrappedBuffer(payload.getBytes())));
} else {
carbonMessage.addHttpContent(new DefaultLastHttpContent());
}
return carbonMessage;
}
use of io.netty.handler.codec.http.DefaultLastHttpContent in project reactor-netty by reactor.
the class HttpClientOperationsTest method addEncoderReplaysLastHttp.
@Test
public void addEncoderReplaysLastHttp() throws Exception {
ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
EmbeddedChannel channel = new EmbeddedChannel();
HttpClientOperations ops = new HttpClientOperations(channel, (response, request) -> null, handler);
ops.addHandler(new JsonObjectDecoder());
channel.writeInbound(new DefaultLastHttpContent(buf));
assertThat(channel.pipeline().names().iterator().next(), is("JsonObjectDecoder$extractor"));
Object content = channel.readInbound();
assertThat(content, instanceOf(ByteBuf.class));
((ByteBuf) content).release();
content = channel.readInbound();
assertThat(content, instanceOf(LastHttpContent.class));
((LastHttpContent) content).release();
assertThat(channel.readInbound(), nullValue());
}
use of io.netty.handler.codec.http.DefaultLastHttpContent in project reactor-netty by reactor.
the class HttpClientOperationsTest method addDecoderReplaysLastHttp.
@Test
public void addDecoderReplaysLastHttp() throws Exception {
ByteBuf buf = Unpooled.copiedBuffer("{\"foo\":1}", CharsetUtil.UTF_8);
EmbeddedChannel channel = new EmbeddedChannel();
HttpClientOperations ops = new HttpClientOperations(channel, (response, request) -> null, handler);
ops.addHandler(new JsonObjectDecoder());
channel.writeInbound(new DefaultLastHttpContent(buf));
assertThat(channel.pipeline().names().iterator().next(), is("JsonObjectDecoder$extractor"));
Object content = channel.readInbound();
assertThat(content, instanceOf(ByteBuf.class));
((ByteBuf) content).release();
content = channel.readInbound();
assertThat(content, instanceOf(LastHttpContent.class));
((LastHttpContent) content).release();
assertThat(channel.readInbound(), nullValue());
}
use of io.netty.handler.codec.http.DefaultLastHttpContent in project netty by netty.
the class Http2StreamFrameToHttpObjectCodecTest method testEncodeDataEndAsClient.
@Test
public void testEncodeDataEndAsClient() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false));
ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
LastHttpContent end = new DefaultLastHttpContent(hello, true);
assertTrue(ch.writeOutbound(end));
Http2DataFrame dataFrame = ch.readOutbound();
try {
assertThat(dataFrame.content().toString(CharsetUtil.UTF_8), is("hello world"));
assertTrue(dataFrame.isEndStream());
} finally {
dataFrame.release();
}
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
use of io.netty.handler.codec.http.DefaultLastHttpContent in project netty by netty.
the class Http2StreamFrameToHttpObjectCodecTest method testEncodeTrailersAsClient.
@Test
public void testEncodeTrailersAsClient() throws Exception {
EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false));
LastHttpContent trailers = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, true);
HttpHeaders headers = trailers.trailingHeaders();
headers.set("key", "value");
assertTrue(ch.writeOutbound(trailers));
Http2HeadersFrame headerFrame = ch.readOutbound();
assertThat(headerFrame.headers().get("key").toString(), is("value"));
assertTrue(headerFrame.isEndStream());
assertThat(ch.readOutbound(), is(nullValue()));
assertFalse(ch.finish());
}
Aggregations