CodeVetter · Repo Unpack · Behavior traces
encode/httpx
These traces follow implementation call order rather than executing scenarios. They cover client startup, an ordinary network request, redirects, authentication retries, cookie persistence, asynchronous application dispatch, and CLI downloads. Cleanup paths determine when connections are released and elapsed time becomes available. Each trace retains material branches such as disabled redirects, streaming mode, and application exceptions.
- Startup: Client.__init__() calls BaseClient.__init__(), checks the h2 dependency when HTTP/2 is enabled, computes proxy mappings, initializes the transport, constructs and sorts mounts; __enter__() changes state to OPENED and enters configured transports.
- Ordinary GET: _api.get() → request() → temporary Client → Client.request() → build_request() → send() → auth loop → redirect loop → _send_single_request() → HTTPTransport.handle_request() → httpcore pool → Response.read().
- Redirect: after response hooks, _send_handling_redirects() invokes _build_redirect_request(), which computes method, URL, headers, stream, and jar cookies. Following consumes the previous body and loops; otherwise next_request is set, and excessive history raises TooManyRedirects.
- Digest challenge: DigestAuth.auth_flow() yields the initial request, checks a 401 for a Digest challenge, parses and caches it, builds Authorization, applies challenge-response cookies, and yields a retry; the client reads intermediate responses and adds them to auth history.
- Cookie persistence: response dispatch calls extract_cookies(); a redirect copies the client jar and removes the previous Cookie header before Request rebuilds it. The inspected login/logout test follows a Set-Cookie redirect, reuses the session, then expires it.
- Async ASGI request: AsyncClient.send() → async auth/redirect loops → _send_single_request() → ASGITransport.handle_async_request(); scope and receive/send callbacks bridge the request to await app(), then collected body parts become an ASGIResponseStream and aread() buffers the result unless streaming.
- CLI download: Click opens the destination in wb mode; main() infers GET or POST when method is omitted, creates Client and its streaming context, installs a trace callback, calls download_response(), and exits 0 for a successful response or 1 otherwise.
- Cleanup: Client.stream()/AsyncClient.stream() close responses in finally; complete raw iteration also closes them. Bound streams record elapsed time and close the underlying stream, while client close/aclose closes the default and mounted transports and marks the client CLOSED.