Skip to main content

run_with_initial_bytes

Function run_with_initial_bytes 

Source
pub async fn run_with_initial_bytes<Transport, Handler, Fut>(
    context: Arc<HttpContext>,
    transport: Transport,
    initial_bytes: Vec<u8>,
    handler: Handler,
) -> Result<Option<Upgrade<Transport>>>
where Transport: AsyncRead + AsyncWrite + Unpin + Send + Sync + 'static, Handler: FnMut(Conn<Transport>) -> Fut, Fut: Future<Output = Conn<Transport>>,
Expand description

Like HttpContext::run, but starts with the supplied bytes pre-filled into the request buffer.

Used by runtime adapters that need to peek the first few bytes off a cleartext TCP stream to decide between HTTP/1.1 and HTTP/2 prior-knowledge dispatch, and then hand those bytes into the HTTP/1 parser without re-reading them.

The mechanism is the same one the keep-alive / pipelining path already uses when a follow-up request arrives on the tail of the previous response: any bytes already in the buffer are consumed by the parser before the next transport read.

§Errors

Same as HttpContext::run — any irrecoverably malformed or noncompliant HTTP/1 request surfaces as an Error.