Home / Class/ HttpContentEncoderTest Class — netty Architecture

HttpContentEncoderTest Class — netty Architecture

Architecture documentation for the HttpContentEncoderTest class in HttpContentEncoderTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  992a26d3_2083_aeb8_4785_63c545814355["HttpContentEncoderTest"]
  8d0422ab_2ced_50d4_047e_96ead2603b15["HttpContentEncoderTest.java"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|defined in| 8d0422ab_2ced_50d4_047e_96ead2603b15
  a711fd23_c773_fc6a_dcc6_319f8cc94234["testSplitContent()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| a711fd23_c773_fc6a_dcc6_319f8cc94234
  81ade038_e333_3fc6_444b_d4464efb49ee["testChunkedContent()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| 81ade038_e333_3fc6_444b_d4464efb49ee
  ba8888db_5508_5202_291b_a9da7c34d648["testChunkedContentWithTrailingHeader()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| ba8888db_5508_5202_291b_a9da7c34d648
  3b87bcc8_d4f5_db86_94e0_233cd3057a31["testFullContentWithContentLength()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| 3b87bcc8_d4f5_db86_94e0_233cd3057a31
  30a04db3_d457_460a_811a_a1a1d6c6975a["testFullContent()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| 30a04db3_d457_460a_811a_a1a1d6c6975a
  afc1557b_2b03_5da6_b162_63534b950d0d["testEmptySplitContent()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| afc1557b_2b03_5da6_b162_63534b950d0d
  aeed9996_2473_220a_bbf3_32ef52fcea5f["testEmptyFullContent()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| aeed9996_2473_220a_bbf3_32ef52fcea5f
  03410af7_989a_dbb6_f66e_4213eacbd1f4["testEmptyFullContentWithTrailer()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| 03410af7_989a_dbb6_f66e_4213eacbd1f4
  f349aaac_aa94_f641_ee74_5532ba3e7472["testEmptyHeadResponse()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| f349aaac_aa94_f641_ee74_5532ba3e7472
  13fe5028_0f73_e3ab_0e9d_e48d393b3636["testHttp304Response()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| 13fe5028_0f73_e3ab_0e9d_e48d393b3636
  282614e0_4357_b8e3_63e9_82cbbbe26782["testConnect200Response()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| 282614e0_4357_b8e3_63e9_82cbbbe26782
  ef1ae554_26a0_53e3_a16f_85bb21dbc52e["testConnectFailureResponse()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| ef1ae554_26a0_53e3_a16f_85bb21dbc52e
  01ea3b13_7667_9eb6_0cd7_c75214a062f8["testHttp1_0()"]
  992a26d3_2083_aeb8_4785_63c545814355 -->|method| 01ea3b13_7667_9eb6_0cd7_c75214a062f8

Relationship Graph

Source Code

codec-http/src/test/java/io/netty/handler/codec/http/HttpContentEncoderTest.java lines 44–463

public class HttpContentEncoderTest {

    private static final class TestEncoder extends HttpContentEncoder {
        @Override
        protected Result beginEncode(HttpResponse httpResponse, String acceptEncoding) {
            return new Result("test", new EmbeddedChannel(new MessageToByteEncoder<ByteBuf>() {
                @Override
                protected void encode(ChannelHandlerContext ctx, ByteBuf in, ByteBuf out) throws Exception {
                    out.writeBytes(String.valueOf(in.readableBytes()).getBytes(CharsetUtil.US_ASCII));
                    in.skipBytes(in.readableBytes());
                }
            }));
        }
    }

    @Test
    public void testSplitContent() throws Exception {
        EmbeddedChannel ch = new EmbeddedChannel(new TestEncoder());
        ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));

        ch.writeOutbound(new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK));
        ch.writeOutbound(new DefaultHttpContent(Unpooled.wrappedBuffer(new byte[3])));
        ch.writeOutbound(new DefaultHttpContent(Unpooled.wrappedBuffer(new byte[2])));
        ch.writeOutbound(new DefaultLastHttpContent(Unpooled.wrappedBuffer(new byte[1])));

        assertEncodedResponse(ch);

        HttpContent chunk;
        chunk = ch.readOutbound();
        assertEquals("3", chunk.content().toString(CharsetUtil.US_ASCII));
        chunk.release();

        chunk = ch.readOutbound();
        assertEquals("2", chunk.content().toString(CharsetUtil.US_ASCII));
        chunk.release();

        chunk = ch.readOutbound();
        assertEquals("1", chunk.content().toString(CharsetUtil.US_ASCII));
        chunk.release();

        chunk = ch.readOutbound();
        assertFalse(chunk.content().isReadable());
        assertInstanceOf(LastHttpContent.class, chunk);
        chunk.release();

        assertNull(ch.readOutbound());
    }

    @Test
    public void testChunkedContent() throws Exception {
        EmbeddedChannel ch = new EmbeddedChannel(new TestEncoder());
        ch.writeInbound(new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/"));

        HttpResponse res = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
        res.headers().set(HttpHeaderNames.TRANSFER_ENCODING, HttpHeaderValues.CHUNKED);
        ch.writeOutbound(res);

        assertEncodedResponse(ch);

        ch.writeOutbound(new DefaultHttpContent(Unpooled.wrappedBuffer(new byte[3])));
        ch.writeOutbound(new DefaultHttpContent(Unpooled.wrappedBuffer(new byte[2])));
        ch.writeOutbound(new DefaultLastHttpContent(Unpooled.wrappedBuffer(new byte[1])));

        HttpContent chunk;
        chunk = ch.readOutbound();
        assertEquals("3", chunk.content().toString(CharsetUtil.US_ASCII));
        chunk.release();

        chunk = ch.readOutbound();
        assertEquals("2", chunk.content().toString(CharsetUtil.US_ASCII));
        chunk.release();

        chunk = ch.readOutbound();
        assertEquals("1", chunk.content().toString(CharsetUtil.US_ASCII));
        assertInstanceOf(HttpContent.class, chunk);
        chunk.release();

        chunk = ch.readOutbound();
        assertFalse(chunk.content().isReadable());
        assertInstanceOf(LastHttpContent.class, chunk);
        chunk.release();

Frequently Asked Questions

What is the HttpContentEncoderTest class?
HttpContentEncoderTest is a class in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpContentEncoderTest.java.
Where is HttpContentEncoderTest defined?
HttpContentEncoderTest is defined in codec-http/src/test/java/io/netty/handler/codec/http/HttpContentEncoderTest.java at line 44.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free