Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .agents/skills/python-proxy-headers/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ with ProxySession(proxy_headers={'X-ProxyMesh-Country': 'US'}) as session:

### httpx

Requires `httpx>=0.28,<1` (`pip install 'python-proxy-headers[httpx]'`). Importing `httpx_proxy` on httpx 1.x raises `ImportError`.

```python
from python_proxy_headers.httpx_proxy import get

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/proxy_integration_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
pip install -e .
pip install urllib3 requests aiohttp httpx pycurl

- name: Run header security unit tests
run: python test_header_security.py
- name: Run header security and httpx guard tests
run: python test_header_security.py && python test_httpx_guard.py

integration:
runs-on: ubuntu-24.04
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Unreleased

- Importing `python_proxy_headers.httpx_proxy` on httpx >= 1 raises `ImportError`. httpx 1.0 removed proxy support. The `[httpx]` extra is `httpx>=0.28,<1`.

## 0.2.4 - 2026-11-09

### Security
Expand Down
7 changes: 6 additions & 1 deletion docs/httpx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ httpx

`HTTPX <https://www.python-httpx.org/>`_ is a fully featured HTTP client for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2. This page describes how to use httpx with proxies and how to send and receive custom proxy headers.

httpx 1.0
---------

httpx 1.0 removes httpcore and proxy support. Importing ``python_proxy_headers.httpx_proxy`` raises ``ImportError``. Install the supported line with ``pip install 'python-proxy-headers[httpx]'`` (``httpx>=0.28,<1``).

Getting Started
---------------

Expand All @@ -14,7 +19,7 @@ This section shows you how to quickly get up and running with proxy headers in h

.. code-block:: bash

pip install python-proxy-headers httpx
pip install 'python-proxy-headers[httpx]'

2. Import the module:

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ classifiers = [
"Topic :: Software Development :: Libraries :: Python Modules",
]

[project.optional-dependencies]
httpx = ["httpx>=0.28,<1"]

[project.urls]
Homepage = "https://github.com/proxymesh/python-proxy-headers"
Changelog = "https://github.com/proxymesh/python-proxy-headers/commits/main/"
Expand Down
10 changes: 9 additions & 1 deletion python_proxy_headers/httpx_proxy.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
import httpx

if not httpx.__version__.startswith("0."):
raise ImportError(
f"python_proxy_headers.httpx_proxy requires httpx>=0.28,<1 (found {httpx.__version__}); "
"httpx 1.0 removed proxy support. Install with: pip install 'python-proxy-headers[httpx]'"
)

from contextlib import contextmanager
from httpcore._sync.http_proxy import HTTPProxy, TunnelHTTPConnection, merge_headers, logger
from httpcore._sync.http11 import HTTP11Connection
Expand Down Expand Up @@ -386,4 +394,4 @@ def stream(method: str,
mounts={'http://': transport, 'https://': transport}
) as client:
with client.stream(method=method, url=url, **kwargs) as response:
yield response
yield response
42 changes: 42 additions & 0 deletions test_httpx_guard.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""httpx >= 1 must raise ImportError when the httpx adapter is imported."""

import os
import subprocess
import sys
import tempfile
import unittest
from pathlib import Path

ROOT = Path(__file__).resolve().parent


class HttpxGuardTests(unittest.TestCase):
def test_httpx_1_dev6_raises_import_error(self) -> None:
fake = Path(tempfile.mkdtemp())
package = fake / "httpx"
package.mkdir()
(package / "__init__.py").write_text(
'__version__ = "1.0.dev6"\n', encoding="utf-8"
)
env = os.environ.copy()
prior = env.get("PYTHONPATH")
parts = [str(fake), str(ROOT)]
if prior:
parts.append(prior)
env["PYTHONPATH"] = os.pathsep.join(parts)
completed = subprocess.run(
[sys.executable, "-c", "import python_proxy_headers.httpx_proxy"],
env=env,
text=True,
capture_output=True,
timeout=30,
check=False,
)
self.assertNotEqual(completed.returncode, 0)
self.assertIn("ImportError", completed.stderr)
self.assertIn("1.0.dev6", completed.stderr)
self.assertIn("python-proxy-headers[httpx]", completed.stderr)


if __name__ == "__main__":
unittest.main()