Skip to content

http ​

An HTTP/1.x proxy inbound (CONNECT and forward requests, Basic authentication, optionally TLS) and an HTTP/1.1 CONNECT client outbound through an upstream proxy (path, headers, tls, Basic). The inbound's server is ours_proto::http (the http-server feature of ours-proto), shared with the mixed inbound; the module builds it with the TLS server of its tls block.

Crateours-mod-http, modules/protocols/http
Binary featureshttp-inbound, http-outbound (http enables both)
Crate featurestls, unstable-ktls — only the TLS of the tests (ours-mod-tls, a dev-dependency); the binary links the crate without them

requires ​

dial (the outbound and the dialers) and tls (the tls block; servers and clients from the factory ours_tls_options::Tls).

provides ​

Blocks (inbounds.http: tls; outbounds.http: tls, dial), Inbound/Outbound with the key http, the schemas inbounds.http, outbounds.http. The inbound's options are ours_proto::http::options::HTTPMixedInboundOptions, shared with mixed.

Syntax: http.

Dependencies ​

ours-proto (http-server), ours-tls-options, ours-api, ours-codec.

Design ​

  • src/lib.rs — MODULE, build_inbound and tls: the TLS server of the tls block (ours_api::tls::TlsServer); a tls object enables TLS regardless of enabled, as in the reference (ours_proto::http::enabled).
  • src/outbound.rs — the CONNECT client; an HTTP/2-only proxy is explicitly not supported, UDP — neither.

The server, in crates/proto/src/http/:

  • inbound.rs — HttpInbound, build, build_mixed(.., socks); TCP only. TLS comes as an Arc<dyn TlsServer> from the module that builds the inbound.
  • server.rs — Server::serve: for mixed a first byte of 4/5 hands the connection to the Socks trait (implemented by ours-mod-mixed); otherwise HTTP. The decision is exact: 4 and 5 do not begin an HTTP method.
  • head.rs — reading the request header like net/http.readRequest, the limit MAX_HEADER_BYTES.
  • destination.rs — where the request goes (CONNECT and forward).
  • forward.rs — forward requests: rewriting the header like Go's Request.Write (origin-form, Host, hop-by-hop, reframing the body), the response without buffering the body.
  • tunnel.rs — Buffered: first gives out the bytes read after the CONNECT header, then lets splice through (implements Splice) — after that the connection is a bare socket again.
  • auth.rs, base64.rs, response.rs, wire.rs — authentication, base64 (Go's StdEncoding through the base64 crate), responses, shared helpers; the outbound takes auth, head, tunnel and wire from here too.

Reload ​

Users are behind an ArcSwap<Authenticator>. The decoder ours_config::listener_with_users moves users out of the block's cold form, so changing them does not rebuild the inbound: hot_changed replaces the list (for mixed — also on the SOCKS side through Socks::users_changed), new connections are checked against the new one, ongoing ones keep their answer.

Limitations ​

The inbound's detour, netns, set_system_proxy, domain_resolver are rejected at build time.

Tests ​

modules/protocols/http/tests/inbound.rs (http and the HTTP side of mixed, an HTTP/1.1 client, the SOCKS side through the test Recording), tests/outbound.rs (through a test HTTP proxy, TCP and TLS); unit tests in most files of crates/proto/src/http/.

GPL-3.0-or-later