Home / Class/ HeaderExtractor Class — netty Architecture

HeaderExtractor Class — netty Architecture

Architecture documentation for the HeaderExtractor class in HAProxyMessageDecoder.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  c5b93e38_c667_01b8_5fff_e0aa6b922c3e["HeaderExtractor"]
  891c9404_8383_1a70_6e1e_6faaf7176a96["HAProxyMessageDecoder.java"]
  c5b93e38_c667_01b8_5fff_e0aa6b922c3e -->|defined in| 891c9404_8383_1a70_6e1e_6faaf7176a96
  a4478b3b_c782_3876_3948_f6c7a615fb9e["HeaderExtractor()"]
  c5b93e38_c667_01b8_5fff_e0aa6b922c3e -->|method| a4478b3b_c782_3876_3948_f6c7a615fb9e
  fd4a5643_1cab_48d9_d711_3a4745d987c7["ByteBuf()"]
  c5b93e38_c667_01b8_5fff_e0aa6b922c3e -->|method| fd4a5643_1cab_48d9_d711_3a4745d987c7
  ad9ae385_906b_3bb5_e1b0_fdbb717bef3e["findEndOfHeader()"]
  c5b93e38_c667_01b8_5fff_e0aa6b922c3e -->|method| ad9ae385_906b_3bb5_e1b0_fdbb717bef3e
  4b0096b8_57a1_aeae_bcda_4ec0c392485e["delimiterLength()"]
  c5b93e38_c667_01b8_5fff_e0aa6b922c3e -->|method| 4b0096b8_57a1_aeae_bcda_4ec0c392485e

Relationship Graph

Source Code

codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessageDecoder.java lines 352–428

    private abstract class HeaderExtractor {
        /** Header max size */
        private final int maxHeaderSize;

        protected HeaderExtractor(int maxHeaderSize) {
            this.maxHeaderSize = maxHeaderSize;
        }

        /**
         * Create a frame out of the {@link ByteBuf} and return it.
         *
         * @param ctx     the {@link ChannelHandlerContext} which this {@link HAProxyMessageDecoder} belongs to
         * @param buffer  the {@link ByteBuf} from which to read data
         * @return frame  the {@link ByteBuf} which represent the frame or {@code null} if no frame could
         *                be created
         * @throws Exception if exceed maxLength
         */
        public ByteBuf extract(ChannelHandlerContext ctx, ByteBuf buffer) throws Exception {
            final int eoh = findEndOfHeader(buffer);
            if (!discarding) {
                if (eoh >= 0) {
                    final int length = eoh - buffer.readerIndex();
                    if (length > maxHeaderSize) {
                        buffer.readerIndex(eoh + delimiterLength(buffer, eoh));
                        failOverLimit(ctx, length);
                        return null;
                    }
                    ByteBuf frame = buffer.readSlice(length);
                    buffer.skipBytes(delimiterLength(buffer, eoh));
                    return frame;
                } else {
                    final int length = buffer.readableBytes();
                    if (length > maxHeaderSize) {
                        discardedBytes = length;
                        buffer.skipBytes(length);
                        discarding = true;
                        if (failFast) {
                            failOverLimit(ctx, "over " + discardedBytes);
                        }
                    }
                    return null;
                }
            } else {
                if (eoh >= 0) {
                    final int length = discardedBytes + eoh - buffer.readerIndex();
                    buffer.readerIndex(eoh + delimiterLength(buffer, eoh));
                    discardedBytes = 0;
                    discarding = false;
                    if (!failFast) {
                        failOverLimit(ctx, "over " + length);
                    }
                } else {
                    discardedBytes += buffer.readableBytes();
                    buffer.skipBytes(buffer.readableBytes());
                }
                return null;
            }
        }

        /**
         * Find the end of the header from the given {@link ByteBuf},the end may be a CRLF, or the length given by the
         * header.
         *
         * @param buffer the buffer to be searched
         * @return {@code -1} if can not find the end, otherwise return the buffer index of end
         */
        protected abstract int findEndOfHeader(ByteBuf buffer);

        /**
         * Get the length of the header delimiter.
         *
         * @param buffer the buffer where delimiter is located
         * @param eoh index of delimiter
         * @return length of the delimiter
         */
        protected abstract int delimiterLength(ByteBuf buffer, int eoh);
    }

Frequently Asked Questions

What is the HeaderExtractor class?
HeaderExtractor is a class in the netty codebase, defined in codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessageDecoder.java.
Where is HeaderExtractor defined?
HeaderExtractor is defined in codec-haproxy/src/main/java/io/netty/handler/codec/haproxy/HAProxyMessageDecoder.java at line 352.

Analyze Your Own Codebase

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

Try Supermodel Free