Skip to content

feat: replace httpx by httpx2 - #4974

Open
Kumzy wants to merge 7 commits into
litestar-org:mainfrom
Kumzy:feat/httpx2
Open

feat: replace httpx by httpx2#4974
Kumzy wants to merge 7 commits into
litestar-org:mainfrom
Kumzy:feat/httpx2

Conversation

@Kumzy

@Kumzy Kumzy commented Aug 10, 2026

Copy link
Copy Markdown
Member

This PR aim to replace httpx for the testing extra by httpx2 library.

As httpx is no longer maintained and won't receive any updates regarding future versions of Python, I suggest to change the library behind the TestClient for the 3.x release.

The API behind is mostly the same


📚 Documentation preview 📚: https://litestar-org.github.io/litestar-docs-preview/4974

Kumzy added 4 commits August 10, 2026 11:12
`httpx2` is the Pydantic-maintained fork of `httpx` 0.28.1 with an
identical public API. Switch the `testing` extra to `httpx2>=2.5` and
rename the imports across `litestar/testing`.

The SSE tests and the jwt header assertions move too: they stop
type-checking the moment `subprocess_*_client` and `AsyncTestClient`
become httpx2 types, and httpx2 2.10 narrowed `Headers.get` to
`str | None`.

`httpx` stays pinned in the dev group until `tools/` and the remaining
direct users migrate.
`client.sse()` landed in httpx2 2.5 and covers what `httpx-sse` gave us,
so drop the dependency.
Retires the temporary `httpx` pin from the dev group; `httpx`, `httpcore`
and `httpx-sse` are no longer resolved at all.
Covers the test client base classes, the `httpx2` logger name, the
`python-httpx2` User-Agent and the new dependency floors.

The CSRF example in the middleware docs stays on `httpx`: it demonstrates
calling a running server with your own client and offers `requests` as an
equal alternative, so it should not track Litestar's test-client choice.
@Kumzy
Kumzy requested review from a team, JacobCoffee and provinzkraut as code owners August 10, 2026 10:49
@codecov

codecov Bot commented Aug 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.19%. Comparing base (cbc0c51) to head (2f63180).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4974   +/-   ##
=======================================
  Coverage   67.19%   67.19%           
=======================================
  Files         293      293           
  Lines       15363    15363           
  Branches     1745     1745           
=======================================
  Hits        10323    10323           
  Misses       4890     4890           
  Partials      150      150           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant