# Behavior traces — encode/httpx

> Canonical page: https://codevetter.com/unpack/httpx/behavior-traces

# Behavior traces — encode/httpx

Scanned commit b5addb64f0161ff6bfe94c124ef76f6a1fba5254 (2026-02-23). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

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. — [httpx/_client.py#L663-L716](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L663-L716) [httpx/_client.py#L1275-L1291](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L1275-L1291)
- 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(). — [httpx/_api.py#L195-L207](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_api.py#L195-L207) [httpx/_api.py#L102-L120](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_api.py#L102-L120) [httpx/_client.py#L811-L925](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L811-L925) [httpx/_transports/default.py#L230-L259](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_transports/default.py#L230-L259)
- 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. — [httpx/_client.py#L475-L515](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L475-L515) [httpx/_client.py#L964-L999](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L964-L999)
- 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. — [httpx/_auth.py#L193-L222](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_auth.py#L193-L222) [httpx/_client.py#L938-L961](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L938-L961)
- 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. — [httpx/_client.py#L475-L491](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L475-L491) [httpx/_client.py#L546-L571](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L546-L571) [httpx/_client.py#L1016-L1024](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L1016-L1024) [tests/client/test_redirects.py#L403-L431](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/tests/client/test_redirects.py#L403-L431)
- 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. — [httpx/_client.py#L1625-L1639](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L1625-L1639) [httpx/_client.py#L1717-L1738](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L1717-L1738) [httpx/_transports/asgi.py#L105-L187](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_transports/asgi.py#L105-L187)
- 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. — [httpx/_main.py#L431-L435](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_main.py#L431-L435) [httpx/_main.py#L475-L506](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_main.py#L475-L506) [httpx/_main.py#L251-L270](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_main.py#L251-L270)
- 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. — [httpx/_client.py#L139-L182](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L139-L182) [httpx/_client.py#L869-L877](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L869-L877) [httpx/_client.py#L1583-L1592](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L1583-L1592) [httpx/_client.py#L1978-L1988](https://github.com/encode/httpx/blob/b5addb64f0161ff6bfe94c124ef76f6a1fba5254/httpx/_client.py#L1978-L1988)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
