@Override
    protected void intercept(@NonNull HttpRequestChain chain, @NonNull ByteBuffer buffer, int index)
            throws IOException {
        if (mLog == null) {
            mLog = new NetBareXLog(Protocol.TCP, chain.request().ip(), chain.request().port());
        }
        if (mRequestHeaderHandled) {
            chain.process(buffer);
            return;
        }
        if (!buffer.hasRemaining()) {
            chain.process(buffer);
            return;
        }
        buffer = mergeRequestBuffer(buffer);
        // Check the part end line.
        int headerEndIndex = Bytes.indexOf(buffer.array(), NetBareUtils.PART_END_BYTES);
        if (headerEndIndex < 0) {
            mLog.w("Http request header data is not enough.");
            // Not found the part end line, maybe the data is not enough, wait next buffer coming.
            pendRequestBuffer(buffer);
        } else {
            mRequestHeaderHandled = true;
            // Check whether the header and the body are in the same buffer.
            boolean hasMultiPart = headerEndIndex < buffer.limit() - NetBareUtils.PART_END_BYTES.length;
            if (hasMultiPart) {
                mLog.w("Multiple http request parts are founded.");
                // Separate the header and body data to two buffers.
                int offset = headerEndIndex + NetBareUtils.PART_END_BYTES.length;
                ByteBuffer headerBuffer = ByteBuffer.wrap(buffer.array(), buffer.position(), offset);
                // Allocate a new buffer, do not use wrap, different buffers will share the same array.
                ByteBuffer bodyBuffer = ByteBuffer.allocate(buffer.limit() - offset);
                bodyBuffer.put(buffer.array(), offset, buffer.limit() - offset);
                bodyBuffer.flip();
                chain.process(headerBuffer);
                chain.process(bodyBuffer);
            } else {
                chain.process(buffer);
            }
        }
    }
Separate HTTP header part and body part into different packets.

@author Megatron King
@since 2018-12-08 15:36
netbare-core/src/main/java/com/github/megatronking/netbare/http/HttpHeaderSeparateInterceptor.java