Home / Class/ HttpRequestDecoderTest Class — netty Architecture

HttpRequestDecoderTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  514322d5_436a_d1ac_6240_1f9cf42934a4["HttpRequestDecoderTest"]
  43820591_3035_52e9_0703_5ef352719610["HttpRequestDecoderTest.java"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|defined in| 43820591_3035_52e9_0703_5ef352719610
  f209c48f_87ad_c26c_c8e8_bcdd6c041e52["createContent()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| f209c48f_87ad_c26c_c8e8_bcdd6c041e52
  703641d3_eb0e_4efe_020d_057bf31de411["testDecodeWholeRequestAtOnceCRLFDelimiters()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 703641d3_eb0e_4efe_020d_057bf31de411
  8a51f2ac_cb87_4165_578d_d5700d9e321c["testDecodeWholeRequestAtOnceLFDelimiters()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 8a51f2ac_cb87_4165_578d_d5700d9e321c
  07e20eab_88ad_9739_8d1b_bfe7d62c53c0["testDecodeWholeRequestAtOnceMixedDelimiters()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 07e20eab_88ad_9739_8d1b_bfe7d62c53c0
  e7234722_6562_b070_aeab_9e50d7a157a9["testDecodeWholeRequestAtOnceFailesWithLFDelimiters()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| e7234722_6562_b070_aeab_9e50d7a157a9
  140bc4df_b72a_35e7_f6fc_b10175d91c96["testDecodeWholeRequestAtOnceFailsWithMixedDelimiters()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 140bc4df_b72a_35e7_f6fc_b10175d91c96
  9f4fd74c_a7ec_3f31_5c42_f82daa7ccb9a["testDecodeWholeRequestAtOnceMixedDelimitersWithIntegerOverflowOnMaxBodySize()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 9f4fd74c_a7ec_3f31_5c42_f82daa7ccb9a
  34f7f372_9526_2e9b_38a2_4361361c218b["testDecodeWholeRequestAtOnce()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 34f7f372_9526_2e9b_38a2_4361361c218b
  ec3907dc_9d31_478a_363c_766ff7a4728c["checkHeaders()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| ec3907dc_9d31_478a_363c_766ff7a4728c
  81a4effb_7aa6_b855_5e53_c2263f974fde["checkHeader()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 81a4effb_7aa6_b855_5e53_c2263f974fde
  2ef53b16_08b3_8da4_39e9_0c8175a1f7db["testDecodeWholeRequestInMultipleStepsCRLFDelimiters()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 2ef53b16_08b3_8da4_39e9_0c8175a1f7db
  0bc1b6ce_3f70_e244_0371_9f24ee7c56a5["testDecodeWholeRequestInMultipleStepsLFDelimiters()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 0bc1b6ce_3f70_e244_0371_9f24ee7c56a5
  2b37f10f_8712_7d4a_27b2_0f1ba003cd78["testDecodeWholeRequestInMultipleStepsMixedDelimiters()"]
  514322d5_436a_d1ac_6240_1f9cf42934a4 -->|method| 2b37f10f_8712_7d4a_27b2_0f1ba003cd78

Relationship Graph

Source Code

codec-http/src/test/java/io/netty/handler/codec/http/HttpRequestDecoderTest.java lines 46–877

public class HttpRequestDecoderTest {
    private static final byte[] CONTENT_CRLF_DELIMITERS = createContent("\r\n");
    private static final byte[] CONTENT_LF_DELIMITERS = createContent("\n");
    private static final byte[] CONTENT_MIXED_DELIMITERS = createContent("\r\n", "\n");
    private static final int CONTENT_LENGTH = 8;

    private static byte[] createContent(String... lineDelimiters) {
        String lineDelimiter;
        String lineDelimiter2;
        if (lineDelimiters.length == 2) {
            lineDelimiter = lineDelimiters[0];
            lineDelimiter2 = lineDelimiters[1];
        } else {
            lineDelimiter = lineDelimiters[0];
            lineDelimiter2 = lineDelimiters[0];
        }
        return ("GET /some/path?foo=bar&wibble=eek HTTP/1.1" + "\r\n" +
                "Upgrade: WebSocket" + lineDelimiter2 +
                "Connection: Upgrade" + lineDelimiter +
                "Host: localhost" + lineDelimiter2 +
                "Accept: */*" + lineDelimiter +
                "Origin: http://localhost:8080" + lineDelimiter +
                "Sec-WebSocket-Key1: 10  28 8V7 8 48     0" + lineDelimiter2 +
                "Sec-WebSocket-Key2: 8 Xt754O3Q3QW 0   _60" + lineDelimiter +
                "Content-Length: " + CONTENT_LENGTH + lineDelimiter2 +
                "\r\n"  +
                "12345678").getBytes(CharsetUtil.US_ASCII);
    }

    @Test
    public void testDecodeWholeRequestAtOnceCRLFDelimiters() {
        testDecodeWholeRequestAtOnce(CONTENT_CRLF_DELIMITERS);
    }

    @Test
    public void testDecodeWholeRequestAtOnceLFDelimiters() {
        testDecodeWholeRequestAtOnce(CONTENT_LF_DELIMITERS);
    }

    @Test
    public void testDecodeWholeRequestAtOnceMixedDelimiters() {
        testDecodeWholeRequestAtOnce(CONTENT_MIXED_DELIMITERS);
    }

    @Test
    public void testDecodeWholeRequestAtOnceFailesWithLFDelimiters() {
        testDecodeWholeRequestAtOnce(CONTENT_LF_DELIMITERS, HttpObjectDecoder.DEFAULT_MAX_HEADER_SIZE, true, true);
    }

    @Test
    public void testDecodeWholeRequestAtOnceFailsWithMixedDelimiters() {
        testDecodeWholeRequestAtOnce(CONTENT_MIXED_DELIMITERS, HttpObjectDecoder.DEFAULT_MAX_HEADER_SIZE, true, true);
    }

    @Test
    public void testDecodeWholeRequestAtOnceMixedDelimitersWithIntegerOverflowOnMaxBodySize() {
        testDecodeWholeRequestAtOnce(CONTENT_MIXED_DELIMITERS, Integer.MAX_VALUE, false, false);
        testDecodeWholeRequestAtOnce(CONTENT_MIXED_DELIMITERS, Integer.MAX_VALUE - 1, false, false);
    }

    private static void testDecodeWholeRequestAtOnce(byte[] content) {
        testDecodeWholeRequestAtOnce(content, HttpObjectDecoder.DEFAULT_MAX_HEADER_SIZE, false, false);
    }

    private static void testDecodeWholeRequestAtOnce(byte[] content, int maxHeaderSize, boolean strictLineParsing,
                                                     boolean expectFailure) {
        HttpDecoderConfig config = new HttpDecoderConfig()
                .setMaxHeaderSize(maxHeaderSize)
                .setStrictLineParsing(strictLineParsing);
        EmbeddedChannel channel = new EmbeddedChannel(new HttpRequestDecoder(config));
        assertTrue(channel.writeInbound(Unpooled.copiedBuffer(content)));
        HttpRequest req = channel.readInbound();
        assertNotNull(req);
        if (expectFailure) {
            assertTrue(req.decoderResult().isFailure());
            assertThat(req.decoderResult().cause()).isInstanceOf(InvalidLineSeparatorException.class);
        } else {
            assertFalse(req.decoderResult().isFailure());
            checkHeaders(req.headers());
            LastHttpContent c = channel.readInbound();
            assertEquals(CONTENT_LENGTH, c.content().readableBytes());

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free