Skip to content

Commit ba345fb

Browse files
authored
Merge branch 'master' into feature/allow-multipart-without-files
2 parents a68d1b5 + 4b23574 commit ba345fb

13 files changed

Lines changed: 66 additions & 46 deletions

docs/advanced/ssl.md

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,7 @@ client = httpx.Client(verify=ctx)
7171

7272
### Working with `SSL_CERT_FILE` and `SSL_CERT_DIR`
7373

74-
Unlike `requests`, the `httpx` package does not automatically pull in [the environment variables `SSL_CERT_FILE` or `SSL_CERT_DIR`](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_set_default_verify_paths.html). If you want to use these they need to be enabled explicitly.
75-
76-
For example...
77-
78-
```python
79-
# Use `SSL_CERT_FILE` or `SSL_CERT_DIR` if configured.
80-
# Otherwise default to certifi.
81-
ctx = ssl.create_default_context(
82-
cafile=os.environ.get("SSL_CERT_FILE", certifi.where()),
83-
capath=os.environ.get("SSL_CERT_DIR"),
84-
)
85-
client = httpx.Client(verify=ctx)
86-
```
74+
`httpx` does respect the `SSL_CERT_FILE` and `SSL_CERT_DIR` environment variables by default. For details, refer to [the section on the environment variables page](../environment_variables.md#ssl_cert_file).
8775

8876
### Making HTTPS requests to a local server
8977

docs/compatibility.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,7 @@ For both query params (`params=`) and form data (`data=`), `requests` supports s
226226
In HTTPX, event hooks may access properties of requests and responses, but event hook callbacks cannot mutate the original request/response.
227227

228228
If you are looking for more control, consider checking out [Custom Transports](advanced/transports.md#custom-transports).
229+
230+
## Exceptions and Errors
231+
232+
`requests` exception hierarchy is slightly different to the `httpx` exception hierarchy. `requests` exposes a top level `RequestException`, where as `httpx` exposes a top level `HTTPError`. see the exceptions exposes in requests [here](https://requests.readthedocs.io/en/latest/_modules/requests/exceptions/). See the `httpx` error hierarchy [here](https://www.python-httpx.org/exceptions/).

docs/environment_variables.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,29 @@ python -c "import httpx; httpx.get('http://example.com')"
5151
python -c "import httpx; httpx.get('http://127.0.0.1:5000/my-api')"
5252
python -c "import httpx; httpx.get('https://www.python-httpx.org')"
5353
```
54+
55+
## `SSL_CERT_FILE`
56+
57+
Valid values: a filename
58+
59+
If this environment variable is set then HTTPX will load
60+
CA certificate from the specified file instead of the default
61+
location.
62+
63+
Example:
64+
65+
```console
66+
SSL_CERT_FILE=/path/to/ca-certs/ca-bundle.crt python -c "import httpx; httpx.get('https://example.com')"
67+
```
68+
69+
## `SSL_CERT_DIR`
70+
71+
Valid values: a directory following an [OpenSSL specific layout](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html).
72+
73+
If this environment variable is set and the directory follows an [OpenSSL specific layout](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html) (ie. you ran `c_rehash`) then HTTPX will load CA certificates from this directory instead of the default location.
74+
75+
Example:
76+
77+
```console
78+
SSL_CERT_DIR=/path/to/ca-certs/ python -c "import httpx; httpx.get('https://example.com')"
79+
```

docs/logging.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ httpx.get("https://www.example.com")
2020
Will send debug level output to the console, or wherever `stdout` is directed too...
2121

2222
```
23-
DEBUG [2024-09-28 17:27:40] httpx - load_ssl_context verify=True cert=None
24-
DEBUG [2024-09-28 17:27:40] httpx - load_verify_locations cafile='/Users/karenpetrosyan/oss/karhttpx/.venv/lib/python3.9/site-packages/certifi/cacert.pem'
2523
DEBUG [2024-09-28 17:27:40] httpcore.connection - connect_tcp.started host='www.example.com' port=443 local_address=None timeout=5.0 socket_options=None
2624
DEBUG [2024-09-28 17:27:41] httpcore.connection - connect_tcp.complete return_value=<httpcore._backends.sync.SyncStream object at 0x101f1e8e0>
2725
DEBUG [2024-09-28 17:27:41] httpcore.connection - start_tls.started ssl_context=SSLContext(verify=True) server_hostname='www.example.com' timeout=5.0
@@ -80,4 +78,4 @@ logging.config.dictConfig(LOGGING_CONFIG)
8078
httpx.get('https://www.example.com')
8179
```
8280

83-
The exact formatting of the debug logging may be subject to change across different versions of `httpx` and `httpcore`. If you need to rely on a particular format it is recommended that you pin installation of these packages to fixed versions.
81+
The exact formatting of the debug logging may be subject to change across different versions of `httpx` and `httpcore`. If you need to rely on a particular format it is recommended that you pin installation of these packages to fixed versions.

docs/third_party_packages.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ Provides authentication classes to be used with HTTPX's [authentication paramete
2424

2525
This package adds caching functionality to HTTPX
2626

27+
### httpx-secure
28+
29+
[GitHub](https://github.com/Zaczero/httpx-secure)
30+
31+
Drop-in SSRF protection for httpx with DNS caching and custom validation support.
32+
2733
### httpx-socks
2834

2935
[GitHub](https://github.com/romis2012/httpx-socks)

httpx/_exceptions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,9 +331,7 @@ class StreamClosed(StreamError):
331331
"""
332332

333333
def __init__(self) -> None:
334-
message = (
335-
"Attempted to read or stream content, but the stream has " "been closed."
336-
)
334+
message = "Attempted to read or stream content, but the stream has been closed."
337335
super().__init__(message)
338336

339337

httpx/_urls.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ def __repr__(self) -> str:
379379

380380
if ":" in userinfo:
381381
# Mask any password component.
382-
userinfo = f'{userinfo.split(":")[0]}:[secure]'
382+
userinfo = f"{userinfo.split(':')[0]}:[secure]"
383383

384384
authority = "".join(
385385
[

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ brotli = [
4343
cli = [
4444
"click==8.*",
4545
"pygments==2.*",
46-
"rich>=10,<14",
46+
"rich>=10,<15",
4747
]
4848
http2 = [
4949
"h2>=3,<5",

requirements.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@ chardet==5.2.0
1111
# Documentation
1212
mkdocs==1.6.1
1313
mkautodoc==0.2.0
14-
mkdocs-material==9.5.47
14+
mkdocs-material==9.6.18
1515

1616
# Packaging
17-
build==1.2.2.post1
18-
twine==6.0.1
17+
build==1.3.0
18+
twine==6.1.0
1919

2020
# Tests & Linting
21-
coverage[toml]==7.6.1
22-
cryptography==44.0.1
23-
mypy==1.13.0
24-
pytest==8.3.4
25-
ruff==0.8.1
26-
trio==0.27.0
21+
coverage[toml]==7.10.6
22+
cryptography==45.0.7
23+
mypy==1.17.1
24+
pytest==8.4.1
25+
ruff==0.12.11
26+
trio==0.31.0
2727
trio-typing==0.10.0
28-
trustme==1.2.0
29-
uvicorn==0.32.1
28+
trustme==1.2.1
29+
uvicorn==0.35.0

tests/client/test_auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ async def test_auth_property() -> None:
326326
async with httpx.AsyncClient(transport=httpx.MockTransport(app)) as client:
327327
assert client.auth is None
328328

329-
client.auth = ("user", "password123") # type: ignore
329+
client.auth = ("user", "password123")
330330
assert isinstance(client.auth, httpx.BasicAuth)
331331

332332
url = "https://example.org/"

0 commit comments

Comments
 (0)