Migrate HTTP client from httpx to httpx2 #25

Closed
opened 2026-06-21 03:01:11 +00:00 by coding-agent-marvin8 · 1 comment
coding-agent-marvin8 commented 2026-06-21 03:01:11 +00:00 (Migrated from codeberg.org)

httpx has seen limited upstream activity. Pydantic's fork httpx2 (v2.4.0) provides a maintained path forward with the same API surface, including HTTP/2 and zstd support.

This replaces httpx[http2]~=0.28.1 with httpx2[http2]~=2.4.0 and updates all import sites in the source and test layers.

httpx has seen limited upstream activity. Pydantic's fork httpx2 (v2.4.0) provides a maintained path forward with the same API surface, including HTTP/2 and zstd support. This replaces `httpx[http2]~=0.28.1` with `httpx2[http2]~=2.4.0` and updates all import sites in the source and test layers.
coding-agent-marvin8 commented 2026-06-21 03:01:23 +00:00 (Migrated from codeberg.org)

Exploration findings

Current usage in src/zaojun/__init__.py:

  • import httpx (line 16)
  • httpx.AsyncClient in 5 type annotations and 1 context manager
  • httpx.HTTPStatusError and httpx.RequestError in one exception handler (line 983)

Test layer:

  • tests/test_get_latest_pypi_version.py and tests/test_vulns.py: use httpx_mock fixture from pytest-httpx, which is pinned to httpx==0.28.*
  • tests/test_check_dependency.py: uses AsyncMock directly, only needs from httpx import HTTPStatusError updated

Plan of attack

  1. Commit 1 (failing): update pyproject.toml pytest group (pytest-httpxpytest-httpx2~=1.0.0), migrate all three test files to httpx2 imports and the respx-backed httpx2_mock fixture. Tests fail because the implementation still imports httpx.
  2. Commit 2 (green): update runtime dep (httpx[http2]~=0.28.1httpx2[http2]~=2.4.0) and replace all httpx references in src/zaojun/__init__.py. Full suite passes.

Note: pytest-httpx2 is a thin respx wrapper; if its transport patching doesn't intercept httpx2 calls, the fallback is a hand-written httpx2.AsyncBaseTransport mock.

**Exploration findings** Current usage in `src/zaojun/__init__.py`: - `import httpx` (line 16) - `httpx.AsyncClient` in 5 type annotations and 1 context manager - `httpx.HTTPStatusError` and `httpx.RequestError` in one exception handler (line 983) Test layer: - `tests/test_get_latest_pypi_version.py` and `tests/test_vulns.py`: use `httpx_mock` fixture from `pytest-httpx`, which is pinned to `httpx==0.28.*` - `tests/test_check_dependency.py`: uses `AsyncMock` directly, only needs `from httpx import HTTPStatusError` updated **Plan of attack** 1. Commit 1 (failing): update `pyproject.toml` pytest group (`pytest-httpx` → `pytest-httpx2~=1.0.0`), migrate all three test files to `httpx2` imports and the respx-backed `httpx2_mock` fixture. Tests fail because the implementation still imports `httpx`. 2. Commit 2 (green): update runtime dep (`httpx[http2]~=0.28.1` → `httpx2[http2]~=2.4.0`) and replace all `httpx` references in `src/zaojun/__init__.py`. Full suite passes. Note: `pytest-httpx2` is a thin respx wrapper; if its transport patching doesn't intercept httpx2 calls, the fallback is a hand-written `httpx2.AsyncBaseTransport` mock.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
marvin8/zaojun#25
No description provided.