@Override
    protected void intercept(@NonNull HttpRequestChain chain, @NonNull ByteBuffer buffer,
                             int index) throws IOException {
        if (!buffer.hasRemaining()) {
            return;
        }
        if (chain.request().httpProtocol() != null) {
            chain.process(buffer);
            return;
        }
        if (index == 0) {
            if (requestHeaderFirstByteNotPassed(buffer.get(buffer.position()))) {
                mCallback.onRequest(chain.request(), buffer);
                return;
            }
            // Sniff request header method
            if (buffer.remaining() >= 7 && requestHeaderMethodNotPassed(buffer)) {
                mCallback.onRequest(chain.request(), buffer);
                return;
            }
            mRealHttpProtocol = true;
            chain.process(buffer);
        } else {
            if (mRealHttpProtocol) {
                chain.process(buffer);
            }  else {
                mCallback.onRequest(chain.request(), buffer);
            }
        }
    }
Detect the plaintext packet header to determine is it the HTTP protocol.

@author Megatron King
@since 2019/1/31 16:13
netbare-core/src/main/java/com/github/megatronking/netbare/http/HttpHeaderSniffInterceptor.java