English
ours-http
crates/http is the HTTP client for what ours downloads and speaks itself: remote rule-sets and DNS over HTTPS (a GET read in full), group probes, subscriptions, and the ws, httpupgrade and grpc-lite tunnels (CONNECT or an HTTP/1.1 upgrade to a raw stream).
Design
- The base is HTTP/1.1: every request has its own connection, closed after the response.
- HTTP/2 keeps one connection to a server in a pool and carries all requests and tunnels over it (
ours-http-clienton top ofours-h2);h2.rs— a request with a streaming body,CONNECTand extendedCONNECT. - The version comes from the
http_client/http_clientsoptions (options.rs,option/http.goof sing-box 1.14.4) and is never silently downgraded: an explicitly chosen version fails where it cannot be spoken;autofalls back to HTTP/1.1. Client::new(a downloader over HTTP/1.1 with headers),with_dialer(its own dialer and certificates),with_outbound(through an outbound — for a rule-set, a DNS server or a probe). TheDialertrait,OutboundDialer;RequestHead,ResponseStream,FullResponse.Options— the version, the pool (pool_settings,idle_timeout,keep_alive_period, windows,max_concurrent_streams), headers,max_body_size(MAX_BODY_SIZE).
Why in crates/ and not in libs/
TLS clients come from the factory the caller passes (ours_tls_options::Tls, which the tls module publishes), dialing — through ours-api outbounds. The protocol part without them is moved out into libs/http-client.
Features
None: TLS is built by the factory the caller passes, so a binary without the tls module's implementation speaks plain HTTP only (crates/http/tests/plaintext.rs).
Who uses it
An optional dependency of the binary (the subscriptions feature) and of the modules subscriptions (runtime), dns (DoH), router (remote rule-sets), group (probe), adblock (list downloads), hysteria2 (masquerade).
Tests
crates/http/tests/: client.rs (through direct to a local server, HTTP and TLS, data in crates/http/tests/data/), h2.rs (against the server of the h2 crate, version selection by ALPN, the 101 upgrade), plaintext.rs (without TLS), stall.rs (a download from a server that stops sending fails instead of waiting forever), network.rs — 4 tests going to the internet, #[ignore], run with --ignored.