CodeVetter · Repo Unpack · Data flow
encode/httpx
Request construction turns caller inputs into normalized URL, header, cookie, extension, and stream objects. Authentication and redirect loops can produce additional exchanges before the final response reaches the caller. Transports preserve raw protocol data and delegate network execution, while response models decode and optionally buffer bodies. State persists through the client cookie jar and connection pools; CLI downloads explicitly write decoded content.
- build_request() merges URL, headers, cookies, and query parameters, inserts a timeout extension unless already supplied, then constructs Request with the merged values and body inputs.
- URL construction validates component types and invokes urlparse(); normalization lowercases scheme, encodes hosts, normalizes ports and paths, and preserves the distinction between absent and empty query strings.
- Request uppercases the method, copies extensions, applies cookie headers, and invokes encode_request(); body selection prefers explicit content, then files, nonempty form data, and JSON, with a deprecated raw-data compatibility branch.
- Body encoders return headers plus a byte stream: known lengths use Content-Length, unknown iterable lengths use chunked transfer, and multipart length becomes unknown when any file length cannot be determined.
- send() resolves timeout/auth policy; each exchange runs request hooks, dispatches through the URL-selected transport, runs response hooks, and either returns, follows a redirect, or exposes next_request.
- HTTPTransport converts raw scheme, host, port, request target, headers, stream, and extensions into httpcore.Request; pool output becomes Response with wrapped response stream and preserved extensions.
- The client attaches the originating request, binds elapsed-time tracking to stream closure, extracts Set-Cookie into its jar, and supplies default text encoding; subsequent requests obtain Cookie headers through CookieJar adapters.
- iter_raw() counts received bytes; iter_bytes() applies content decoding and chunking; read() joins decoded chunks into cached content. CLI download_response() writes iter_bytes() chunks while reporting raw-byte progress.