Skip to content

Commit 4dd7928

Browse files
author
Patrick J. McNerthney
committed
Update network backend examples to use httpcore.MackBackend
1 parent 0ec032d commit 4dd7928

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

docs/advanced/transports.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,14 @@ connecting via a Unix Domain Socket that is only available via this low-level AP
3838
Another advanced configuration is supplying a custom httpcore [Network Backend](https://www.encode.io/httpcore/network-backends/).
3939

4040
```pycon
41+
>>> import httpcore
4142
>>> import httpx
42-
>>> import myk8s
43-
>>> # This custom network backend enables remote access to ports inside a Kubernetes Cluster using pod port forwarding.
44-
>>> backend = myk8s.NetworkBackend('cluster.local')
43+
>>> backend = httpcore.MockBackend([b"HTTP/1.1 200 OK\r\n\r\nHello, World!"])
4544
>>> transport = httpx.HTTPTransport(network_backend=backend)
4645
>>> client = httpx.Client(transport=transport)
47-
>>> response = client.get("http://argocd-server.argocd.svc.cluster.local")
46+
>>> response = client.get("http://network-backend")
47+
>>> reposne.text
48+
'Hello, World!'
4849
```
4950

5051
## WSGI Transport

httpx/_transports/default.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,12 @@
2525
client = httpx.Client(transport=transport)
2626
2727
# Using advanced httpcore configuration, with custom network backend.
28-
import myk8s
29-
backend = myk8s.NetworkBackend('cluster.local')
28+
import httpcore
29+
backend = backend = httpcore.MockBackend([b"HTTP/1.1 200 OK\r\n\r\nHello, World!"])
3030
transport = httpx.HTTPTransport(network_backend=backend)
3131
client = httpx.Client(transport=transport)
32-
response = client.get("http://argocd-server.argocd.svc.cluster.local")
32+
response = client.get("http://network-backend")
33+
content = response.text
3334
"""
3435

3536
from __future__ import annotations

0 commit comments

Comments
 (0)