private void parseResponseHeader(HttpSession session, ByteBuffer buffer) {
        session.resBodyOffset = buffer.remaining();
        String headerString = new String(buffer.array(), buffer.position(), buffer.remaining());
        // In some condition, no request but has response, we set the method to unknown.
        if (session.method == null) {
            session.method = HttpMethod.UNKNOWN;
        }
        String[] headers = headerString.split(NetBareUtils.LINE_END_REGEX);
        String[] responseLine = headers[0].split(" ");
        if (responseLine.length < 2) {
            mLog.w("Unexpected http response line: " + headers[0]);
            return;
        }
        // Http Protocol
        HttpProtocol protocol = HttpProtocol.parse(responseLine[0]);
        if (protocol == HttpProtocol.UNKNOWN) {
            mLog.w("Unknown http response protocol: " + responseLine[0]);
            return;
        }
        if (session.protocol != protocol) {
            // Protocol downgrade
            if (session.protocol != null) {
                mLog.w("Unmatched http protocol, request is " + session.protocol +
                        " but response is " + responseLine[0]);
            }
            session.protocol = protocol;
        }
        // Code
        int code = NetBareUtils.parseInt(responseLine[1], -1);
        if (code == -1) {
            mLog.w("Unexpected http response code: " + responseLine[1]);
            return;
        }
        session.code = code;
        // Message
        session.message = headers[0].replaceFirst(responseLine[0], "")
                .replaceFirst(responseLine[1], "").trim();

        // Http response headers
        if (headers.length <= 1) {
            mLog.w("Unexpected http response headers.");
            return;
        }
        for (int i = 1; i < headers.length; i++) {
            String responseHeader = headers[i];
            // Reach the header end
            if (responseHeader.isEmpty()) {
                continue;
            }
            String[] nameValue = responseHeader.split(":");
            if (nameValue.length < 2) {
                mLog.w("Unexpected http response header: " + responseHeader);
                continue;
            }
            String name = nameValue[0].trim();
            String value = responseHeader.replaceFirst(nameValue[0] + ": ", "").trim();
            List<String> header = session.responseHeaders.get(name);
            if (header == null) {
                header = new ArrayList<>(1);
                session.responseHeaders.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