Update network backend examples to use httpcore.MackBackend

This commit is contained in:
Patrick J. McNerthney 2026-01-27 12:35:20 -10:00
parent 0ec032d724
commit 4dd7928af9
2 changed files with 9 additions and 7 deletions

View File

@ -38,13 +38,14 @@ connecting via a Unix Domain Socket that is only available via this low-level AP
Another advanced configuration is supplying a custom httpcore [Network Backend](https://www.encode.io/httpcore/network-backends/).
```pycon
>>> import httpcore
>>> import httpx
>>> import myk8s
>>> # This custom network backend enables remote access to ports inside a Kubernetes Cluster using pod port forwarding.
>>> backend = myk8s.NetworkBackend('cluster.local')
>>> backend = httpcore.MockBackend([b"HTTP/1.1 200 OK\r\n\r\nHello, World!"])
>>> transport = httpx.HTTPTransport(network_backend=backend)
>>> client = httpx.Client(transport=transport)
>>> response = client.get("http://argocd-server.argocd.svc.cluster.local")
>>> response = client.get("http://network-backend")
>>> reposne.text
'Hello, World!'
```
## WSGI Transport

View File

@ -25,11 +25,12 @@ transport = httpx.HTTPTransport(uds="socket.uds")
client = httpx.Client(transport=transport)
# Using advanced httpcore configuration, with custom network backend.
import myk8s
backend = myk8s.NetworkBackend('cluster.local')
import httpcore
backend = backend = httpcore.MockBackend([b"HTTP/1.1 200 OK\r\n\r\nHello, World!"])
transport = httpx.HTTPTransport(network_backend=backend)
client = httpx.Client(transport=transport)
response = client.get("http://argocd-server.argocd.svc.cluster.local")
response = client.get("http://network-backend")
content = response.text
"""
from __future__ import annotations