Search in sources :

Example 31 with LastHttpContent

use of io.netty.handler.codec.http.LastHttpContent in project netty by netty.

the class Http2StreamFrameToHttpObjectCodecTest method testUpgradeEmptyEnd.

@Test
public void testUpgradeEmptyEnd() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(true));
    LastHttpContent end = LastHttpContent.EMPTY_LAST_CONTENT;
    assertTrue(ch.writeOutbound(end));
    Http2DataFrame emptyFrame = ch.readOutbound();
    try {
        assertThat(emptyFrame.content().readableBytes(), is(0));
        assertTrue(emptyFrame.isEndStream());
    } finally {
        emptyFrame.release();
    }
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.jupiter.api.Test)

Example 32 with LastHttpContent

use of io.netty.handler.codec.http.LastHttpContent in project netty by netty.

the class Http2StreamFrameToHttpObjectCodecTest method testDowngradeTrailers.

@Test
public void testDowngradeTrailers() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(true));
    Http2Headers headers = new DefaultHttp2Headers();
    headers.set("key", "value");
    assertTrue(ch.writeInbound(new DefaultHttp2HeadersFrame(headers, true)));
    LastHttpContent trailers = ch.readInbound();
    try {
        assertThat(trailers.content().readableBytes(), is(0));
        assertThat(trailers.trailingHeaders().get("key"), is("value"));
        assertFalse(trailers instanceof FullHttpRequest);
    } finally {
        trailers.release();
    }
    assertThat(ch.readInbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.jupiter.api.Test)

Example 33 with LastHttpContent

use of io.netty.handler.codec.http.LastHttpContent in project netty by netty.

the class Http2StreamFrameToHttpObjectCodecTest method testDecodeResponseTrailersAsClient.

@Test
public void testDecodeResponseTrailersAsClient() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false));
    Http2Headers headers = new DefaultHttp2Headers();
    headers.set("key", "value");
    assertTrue(ch.writeInbound(new DefaultHttp2HeadersFrame(headers, true)));
    LastHttpContent trailers = ch.readInbound();
    try {
        assertThat(trailers.content().readableBytes(), is(0));
        assertThat(trailers.trailingHeaders().get("key"), is("value"));
        assertFalse(trailers instanceof FullHttpRequest);
    } finally {
        trailers.release();
    }
    assertThat(ch.readInbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.jupiter.api.Test)

Example 34 with LastHttpContent

use of io.netty.handler.codec.http.LastHttpContent in project netty by netty.

the class Http2StreamFrameToHttpObjectCodecTest method testDecodeDataAsClient.

@Test
public void testDecodeDataAsClient() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false));
    ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8);
    assertTrue(ch.writeInbound(new DefaultHttp2DataFrame(hello)));
    HttpContent content = ch.readInbound();
    try {
        assertThat(content.content().toString(CharsetUtil.UTF_8), is("hello world"));
        assertFalse(content instanceof LastHttpContent);
    } finally {
        content.release();
    }
    assertThat(ch.readInbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ByteBuf(io.netty.buffer.ByteBuf) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) DefaultHttpContent(io.netty.handler.codec.http.DefaultHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.jupiter.api.Test)

Example 35 with LastHttpContent

use of io.netty.handler.codec.http.LastHttpContent in project netty by netty.

the class Http2StreamFrameToHttpObjectCodecTest method testEncodeEmptyEndAsClient.

@Test
public void testEncodeEmptyEndAsClient() throws Exception {
    EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false));
    LastHttpContent end = LastHttpContent.EMPTY_LAST_CONTENT;
    assertTrue(ch.writeOutbound(end));
    Http2DataFrame emptyFrame = ch.readOutbound();
    try {
        assertThat(emptyFrame.content().readableBytes(), is(0));
        assertTrue(emptyFrame.isEndStream());
    } finally {
        emptyFrame.release();
    }
    assertThat(ch.readOutbound(), is(nullValue()));
    assertFalse(ch.finish());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) DefaultLastHttpContent(io.netty.handler.codec.http.DefaultLastHttpContent) Test(org.junit.jupiter.api.Test)

Aggregations

LastHttpContent (io.netty.handler.codec.http.LastHttpContent)122 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)56 HttpContent (io.netty.handler.codec.http.HttpContent)52 ByteBuf (io.netty.buffer.ByteBuf)40 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)38 HttpResponse (io.netty.handler.codec.http.HttpResponse)38 HttpRequest (io.netty.handler.codec.http.HttpRequest)31 Test (org.junit.Test)27 DefaultHttpContent (io.netty.handler.codec.http.DefaultHttpContent)21 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)19 Test (org.junit.jupiter.api.Test)19 FullHttpResponse (io.netty.handler.codec.http.FullHttpResponse)17 DefaultFullHttpResponse (io.netty.handler.codec.http.DefaultFullHttpResponse)13 HttpObject (io.netty.handler.codec.http.HttpObject)10 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)9 ChannelFuture (io.netty.channel.ChannelFuture)9 DefaultFullHttpRequest (io.netty.handler.codec.http.DefaultFullHttpRequest)9 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)9 FullHttpRequest (io.netty.handler.codec.http.FullHttpRequest)9 IOException (java.io.IOException)9