English
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.
| Crate | ours-mod-http, modules/protocols/http |
| Binary features | http-inbound, http-outbound (http enables both) |
| Crate features | tls, 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_inboundandtls: the TLS server of thetlsblock (ours_api::tls::TlsServer); atlsobject enables TLS regardless ofenabled, as in the reference (ours_proto::http::enabled).src/outbound.rs— theCONNECTclient; 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 anArc<dyn TlsServer>from the module that builds the inbound.server.rs—Server::serve: formixeda first byte of4/5hands the connection to theSockstrait (implemented byours-mod-mixed); otherwise HTTP. The decision is exact:4and5do not begin an HTTP method.head.rs— reading the request header likenet/http.readRequest, the limitMAX_HEADER_BYTES.destination.rs— where the request goes (CONNECTand forward).forward.rs— forward requests: rewriting the header like Go'sRequest.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 theCONNECTheader, then lets splice through (implementsSplice) — after that the connection is a bare socket again.auth.rs,base64.rs,response.rs,wire.rs— authentication, base64 (Go'sStdEncodingthrough thebase64crate), responses, shared helpers; the outbound takesauth,head,tunnelandwirefrom 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/.