private void parseRequestHeader(HttpSession session, ByteBuffer buffer) {
        session.reqBodyOffset = buffer.remaining();
        String headerString = new String(buffer.array(), buffer.position(), buffer.remaining());
        String[] headers = headerString.split(NetBareUtils.LINE_END_REGEX);
        String[] requestLine = headers[0].split(" ");
        if (requestLine.length < 3) {
            mLog.w("Unexpected http request line: " + headers[0]);
            return;
        }
        // Method
        HttpMethod method = HttpMethod.parse(requestLine[0]);
        if (method == HttpMethod.UNKNOWN) {
            mLog.w("Unknown http request method: " + requestLine[0]);
            return;
        }
        session.method = method;
        // Http Protocol
        HttpProtocol protocol = HttpProtocol.parse(requestLine[requestLine.length - 1]);
        if (protocol == HttpProtocol.UNKNOWN) {
            mLog.w("Unknown http request protocol: " + requestLine[requestLine.length - 1]);
            return;
        }
        session.protocol = protocol;

        // Path
        session.path = headers[0].replace(requestLine[0], "")
                .replace(requestLine[requestLine.length - 1], "")
                .trim();

        // Http request headers
        if (headers.length <= 1) {
            mLog.w("Unexpected http request headers.");
            return;
        }
        for (int i = 1; i < headers.length; i++) {
            String requestHeader = headers[i];
            // Reach the header end
            if (requestHeader.isEmpty()) {
                continue;
            }
            String[] nameValue = requestHeader.split(":");
            if (nameValue.length < 2) {
                mLog.w("Unexpected http request header: " + requestHeader);
                continue;
            }
            String name = nameValue[0].trim();
            String value = requestHeader.replaceFirst(nameValue[0] + ": ", "").trim();
            List<String> header = session.requestHeaders.get(name);
            if (header == null) {
                header = new ArrayList<>(1);
                session.requestHeaders.put(name, header);
            }
            header.add(value);
        }
    }
Parse HTTP request header part and response header part from HTTP packets. The parse result will
 be set to {@link HttpSession}.

@author Megatron King
@since 2018-12-09 12:19
netbare-core/src/main/java/com/github/megatronking/netbare/http/HttpHeaderParseInterceptor.java