Skip to content

ours-http-client ​

libs/http-client — HTTP for a client that brings its own connections: requests and upgrades over HTTP/1.1 on top of a stream, and a pool of HTTP/2 connections per server with their streams.

The boundary with ours-http ​

Here — only the protocol on top of an already open Io (AsyncRead + AsyncWrite + Send + Unpin): who dials and how TLS is set up does not matter to the library (Secured marks a secured connection). Dialing through an outbound, TLS from ours-mod-tls and the http_client options are in ours-http, which depends on a module and therefore lives in crates/.

The API in outline ​

  • http1 — one request and the response head, then the body by Content-Length, chunked or until close: read_head, read_body, Head, Body, MAX_HEAD.
  • h2 — HTTP/2 streams on top of ours-h2 (sing-box 1.14.4's common/httpclient): a tunnel or a request body as a byte stream (BodyStream), send_body, headers, parse_uri, split.
  • pool — Pool, Conn, Slot, Settings: one connection to a server at a time with its own driver task, reused until GOAWAY, a break or idling longer than idle_timeout. Keep-alive — like x/net's http2.Transport with sing-box's settings: a PING after keep_alive_period of silence, closing if the pong did not arrive within idle_timeout. Closing an idle connection is our own addition (x/net does not do it): it keeps an abandoned pool from holding a socket. The pool remembers a server's refusal of extended CONNECT.
  • url::Url — only http/https: the scheme, where to connect, the path and the query.
  • Error — distinguishes errors by what the caller can do: a fallback to HTTP/1.1 is legitimate only when the server does not speak the requested version.

Who uses it ​

Only ours-http.

Tests ​

Unit tests in src/ (http1, pool, url); fuzz targets in fuzz/ (response, chunked_roundtrip).

GPL-3.0-or-later