public T parse()

in httpcore5/src/main/java/org/apache/hc/core5/http/impl/nio/AbstractMessageParser.java [155:206]


    public T parse(
            final SessionInputBuffer sessionBuffer, final boolean endOfStream) throws IOException, HttpException {
        Args.notNull(sessionBuffer, "Session input buffer");
        while (this.state != State.COMPLETED) {
            if (this.lineBuf == null) {
                this.lineBuf = new CharArrayBuffer(64);
            } else {
                this.lineBuf.clear();
            }
            final boolean lineComplete = sessionBuffer.readLine(this.lineBuf, endOfStream);
            final int maxLineLen = this.http1Config.getMaxLineLength();
            if (maxLineLen > 0 &&
                    (this.lineBuf.length() > maxLineLen ||
                            !lineComplete && sessionBuffer.length() > maxLineLen)) {
                throw new MessageConstraintException("Maximum line length limit exceeded");
            }
            if (!lineComplete) {
                break;
            }

            switch (this.state) {
            case READ_HEAD_LINE:
                this.message = parseHeadLine();
                if (this.message != null) {
                    this.state = State.READ_HEADERS;
                }
                break;
            case READ_HEADERS:
                if (this.lineBuf.length() > 0) {
                    final int maxHeaderCount = this.http1Config.getMaxHeaderCount();
                    if (maxHeaderCount > 0 && headerBufs.size() >= maxHeaderCount) {
                        throw new MessageConstraintException("Maximum header count exceeded");
                    }

                    parseHeader();
                } else {
                    this.state = State.COMPLETED;
                }
                break;
            }
            if (endOfStream && !sessionBuffer.hasData()) {
                this.state = State.COMPLETED;
            }
        }
        if (this.state == State.COMPLETED) {
            for (final CharArrayBuffer buffer : this.headerBufs) {
                this.message.addHeader(this.lineParser.parseHeader(buffer));
            }
            return this.message;
        }
        return null;
    }