Phase 6: HTTP/1.1 Client with Connection Pooling#
Implement the high-level HTTP/1.1 client in the net crate, bringing together TCP, TLS, DNS, URL, and HTTP parsing.
Requirements#
- HttpClient type:
get(url: &Url) -> Result<HttpResponse>post(url: &Url, body: &[u8], content_type: &str) -> Result<HttpResponse>request(method: Method, url: &Url, headers: &Headers, body: Option<&[u8]>) -> Result<HttpResponse>
- Scheme handling:
http://— plain TCP connectionhttps://— TLS connection with certificate verification
- Connection lifecycle:
- DNS resolve hostname → connect TCP → (optional TLS handshake) → send request → read response
- Respect
Connection: keep-alive/Connection: closeheaders
- Connection pooling:
- Pool idle connections by (host, port, is_tls) key
- Reuse connections for subsequent requests to same origin
- Max idle time before closing (e.g., 60 seconds)
- Max connections per host (e.g., 6)
- Redirect following: follow 301, 302, 307, 308 redirects (configurable max redirects)
- User-Agent:
we-browser/0.1
Dependencies#
- WHATWG URL parser
- TCP socket wrapper
- DNS stub resolver
- TLS 1.3 client (handshake + record layer + key schedule)
- HTTP/1.1 parser
Acceptance Criteria#
- Fetch HTTP URLs over plain TCP
- Fetch HTTPS URLs with TLS 1.3
- Connection pooling with keep-alive reuse
- Redirect following (301, 302, 307, 308)
- Proper Host header from URL
- Timeout support for connect and read
- Integration test: fetch a real HTTPS page
- Tests (15+ unit tests + integration tests)
-
cargo clippyandcargo fmtclean