Java Code Examples for io.netty.handler.codec.http.LastHttpContent#release()
The following examples show how to use
io.netty.handler.codec.http.LastHttpContent#release() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpPostRequestDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Test public void testFormEncodeIncorrect() throws Exception { LastHttpContent content = new DefaultLastHttpContent( Unpooled.copiedBuffer("project=netty&&project=netty", CharsetUtil.US_ASCII)); DefaultHttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/"); HttpPostRequestDecoder decoder = new HttpPostRequestDecoder(req); try { decoder.offer(content); fail(); } catch (HttpPostRequestDecoder.ErrorDataDecoderException e) { assertTrue(e.getCause() instanceof IllegalArgumentException); } finally { decoder.destroy(); content.release(); } }
Example 2
Source File: Http2StreamFrameToHttpObjectCodecTest.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@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()); }
Example 3
Source File: Http2StreamFrameToHttpObjectCodecTest.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Test public void testDowngradeEndData() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(true)); ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8); assertTrue(ch.writeInbound(new DefaultHttp2DataFrame(hello, true))); LastHttpContent content = ch.readInbound(); try { assertThat(content.content().toString(CharsetUtil.UTF_8), is("hello world")); assertTrue(content.trailingHeaders().isEmpty()); } finally { content.release(); } assertThat(ch.readInbound(), is(nullValue())); assertFalse(ch.finish()); }
Example 4
Source File: Http2StreamFrameToHttpObjectCodecTest.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@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()); }
Example 5
Source File: Http2StreamFrameToHttpObjectCodecTest.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Test public void testDecodeEndDataAsClient() throws Exception { EmbeddedChannel ch = new EmbeddedChannel(new Http2StreamFrameToHttpObjectCodec(false)); ByteBuf hello = Unpooled.copiedBuffer("hello world", CharsetUtil.UTF_8); assertTrue(ch.writeInbound(new DefaultHttp2DataFrame(hello, true))); LastHttpContent content = ch.readInbound(); try { assertThat(content.content().toString(CharsetUtil.UTF_8), is("hello world")); assertTrue(content.trailingHeaders().isEmpty()); } finally { content.release(); } assertThat(ch.readInbound(), is(nullValue())); assertFalse(ch.finish()); }
Example 6
Source File: WebSocketServerHandshaker00Test.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private static void testPerformOpeningHandshake0(boolean subProtocol) { EmbeddedChannel ch = new EmbeddedChannel( new HttpObjectAggregator(42), new HttpRequestDecoder(), new HttpResponseEncoder()); FullHttpRequest req = new DefaultFullHttpRequest( HTTP_1_1, HttpMethod.GET, "/chat", Unpooled.copiedBuffer("^n:ds[4U", CharsetUtil.US_ASCII)); req.headers().set(HttpHeaderNames.HOST, "server.example.com"); req.headers().set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET); req.headers().set(HttpHeaderNames.CONNECTION, "Upgrade"); req.headers().set(HttpHeaderNames.ORIGIN, "http://example.com"); req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY1, "4 @1 46546xW%0l 1 5"); req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00"); req.headers().set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "chat, superchat"); if (subProtocol) { new WebSocketServerHandshaker00( "ws://example.com/chat", "chat", Integer.MAX_VALUE).handshake(ch, req); } else { new WebSocketServerHandshaker00( "ws://example.com/chat", null, Integer.MAX_VALUE).handshake(ch, req); } EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder()); ch2.writeInbound(ch.readOutbound()); HttpResponse res = ch2.readInbound(); Assert.assertEquals("ws://example.com/chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_LOCATION)); if (subProtocol) { Assert.assertEquals("chat", res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); } else { Assert.assertNull(res.headers().get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL)); } LastHttpContent content = ch2.readInbound(); Assert.assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII)); content.release(); req.release(); }
Example 7
Source File: WebSocketServerHandshaker00Test.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
private static void testPerformOpeningHandshake0(boolean subProtocol) { EmbeddedChannel ch = new EmbeddedChannel( new HttpObjectAggregator(42), new HttpRequestDecoder(), new HttpResponseEncoder()); FullHttpRequest req = ReferenceCountUtil.releaseLater(new DefaultFullHttpRequest( HTTP_1_1, HttpMethod.GET, "/chat", Unpooled.copiedBuffer("^n:ds[4U", CharsetUtil.US_ASCII))); req.headers().set(Names.HOST, "server.example.com"); req.headers().set(Names.UPGRADE, WEBSOCKET.toLowerCase()); req.headers().set(Names.CONNECTION, "Upgrade"); req.headers().set(Names.ORIGIN, "http://example.com"); req.headers().set(Names.SEC_WEBSOCKET_KEY1, "4 @1 46546xW%0l 1 5"); req.headers().set(Names.SEC_WEBSOCKET_KEY2, "12998 5 Y3 1 .P00"); req.headers().set(Names.SEC_WEBSOCKET_PROTOCOL, "chat, superchat"); if (subProtocol) { new WebSocketServerHandshaker00( "ws://example.com/chat", "chat", Integer.MAX_VALUE).handshake(ch, req); } else { new WebSocketServerHandshaker00( "ws://example.com/chat", null, Integer.MAX_VALUE).handshake(ch, req); } EmbeddedChannel ch2 = new EmbeddedChannel(new HttpResponseDecoder()); ch2.writeInbound(ch.readOutbound()); HttpResponse res = (HttpResponse) ch2.readInbound(); Assert.assertEquals("ws://example.com/chat", res.headers().get(Names.SEC_WEBSOCKET_LOCATION)); if (subProtocol) { Assert.assertEquals("chat", res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL)); } else { Assert.assertNull(res.headers().get(Names.SEC_WEBSOCKET_PROTOCOL)); } LastHttpContent content = (LastHttpContent) ch2.readInbound(); Assert.assertEquals("8jKS'y:G*Co,Wxa-", content.content().toString(CharsetUtil.US_ASCII)); content.release(); }