Home / Function/ encodeInitialLine() — netty Function Reference

encodeInitialLine() — netty Function Reference

Architecture documentation for the encodeInitialLine() function in HttpRequestEncoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  41692290_ce43_dba3_2424_a992a23e8684["encodeInitialLine()"]
  161b2c86_34d5_a1fc_3893_b52b82c67020["HttpRequestEncoder"]
  41692290_ce43_dba3_2424_a992a23e8684 -->|defined in| 161b2c86_34d5_a1fc_3893_b52b82c67020
  style 41692290_ce43_dba3_2424_a992a23e8684 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java lines 39–79

    @Override
    protected void encodeInitialLine(ByteBuf buf, HttpRequest request) throws Exception {
        ByteBufUtil.copy(request.method().asciiName(), buf);

        String uri = request.uri();

        if (uri.isEmpty()) {
            // Add " / " as absolute path if uri is not present.
            // See https://tools.ietf.org/html/rfc2616#section-5.1.2
            ByteBufUtil.writeMediumBE(buf, SPACE_SLASH_AND_SPACE_MEDIUM);
        } else {
            CharSequence uriCharSequence = uri;
            boolean needSlash = false;
            int start = uri.indexOf("://");
            if (start != -1 && uri.charAt(0) != SLASH) {
                start += 3;
                // Correctly handle query params.
                // See https://github.com/netty/netty/issues/2732
                int index = uri.indexOf(QUESTION_MARK, start);
                if (index == -1) {
                    if (uri.lastIndexOf(SLASH) < start) {
                        needSlash = true;
                    }
                } else {
                    if (uri.lastIndexOf(SLASH, index) < start) {
                        uriCharSequence = new StringBuilder(uri).insert(index, SLASH);
                    }
                }
            }
            buf.writeByte(SP).writeCharSequence(uriCharSequence, CharsetUtil.UTF_8);
            if (needSlash) {
                // write "/ " after uri
                ByteBufUtil.writeShortBE(buf, SLASH_AND_SPACE_SHORT);
            } else {
                buf.writeByte(SP);
            }
        }

        request.protocolVersion().encode(buf);
        ByteBufUtil.writeShortBE(buf, CRLF_SHORT);
    }

Subdomains

Frequently Asked Questions

What does encodeInitialLine() do?
encodeInitialLine() is a function in the netty codebase, defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java.
Where is encodeInitialLine() defined?
encodeInitialLine() is defined in codec-http/src/main/java/io/netty/handler/codec/http/HttpRequestEncoder.java at line 39.

Analyze Your Own Codebase

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

Try Supermodel Free