Module H2_conpool_handler

HTTP/2 Protocol Handler for Conpool.

This module provides a protocol handler that enables HTTP/2 connection multiplexing through Conpool's typed pool API. It manages H2_client instances and supports concurrent stream multiplexing.

Key features:

val src : Logs.src
module Log : Logs.LOG

State Type

type h2_state = {
  1. client : H2_client.t;
    (*

    The underlying HTTP/2 client.

    *)
  2. flow : Conpool.Config.connection_flow;
    (*

    The connection flow (needed for H2 operations).

    *)
  3. sw : Eio.Switch.t;
    (*

    Connection-lifetime switch for the reader fiber.

    *)
  4. mutable reader_started : bool;
    (*

    Whether the background reader fiber has been started.

    *)
  5. mutable goaway_received : bool;
    (*

    Whether GOAWAY has been received from peer.

    *)
  6. mutable last_goaway_stream : int32;
    (*

    Last stream ID from GOAWAY (streams > this may be retried).

    *)
  7. mutable last_goaway_code : H2_frame.error_code;
    (*

    Error code from the last GOAWAY frame.

    *)
  8. mutable max_concurrent_streams : int;
    (*

    Cached max_concurrent_streams from peer settings.

    *)
}

HTTP/2 connection state managed by Conpool. This wraps H2_client.t with additional tracking for stream management.

Protocol Configuration

val init_state : sw:Eio.Switch.t -> flow:[ `Close | `Flow | `R | `Shutdown | `W ] Eio.Resource.t -> tls_epoch:'a -> h2_state

Initialize HTTP/2 state for a new connection. Performs the HTTP/2 handshake and extracts peer settings. The sw parameter is a connection-lifetime switch that will be used to spawn the background reader fiber when on_acquire is called.

val on_acquire : h2_state -> unit

Called when a connection is acquired from the pool. Starts the background reader fiber on first acquisition.

val on_release : 'a -> unit

Called when a connection is released back to the pool. For HTTP/2, this is a no-op since the reader keeps running.

val is_healthy : h2_state -> bool

Check if the HTTP/2 connection is still healthy.

val on_close : h2_state -> unit

Cleanup when connection is destroyed.

Get access mode for this connection. HTTP/2 supports multiplexing: multiple concurrent streams per connection.

The protocol configuration for HTTP/2 connections.

Request Functions

val request : state:h2_state -> uri:Uri.t -> headers:Headers.t -> ?body:Body.t -> method_:Method.t -> auto_decompress:bool -> unit -> (H2_adapter.response, Error.error) result

Make an HTTP/2 request using the pooled connection state.

Uses the concurrent request path with the connection-lifetime reader fiber. Multiple requests can be made concurrently on the same connection.

  • parameter state

    The HTTP/2 state from Conpool

  • parameter uri

    Request URI

  • parameter headers

    Request headers

  • parameter body

    Optional request body

  • parameter method_

    HTTP method

  • parameter auto_decompress

    Whether to decompress response body

  • returns

    Response or structured error