From 4dd7928af996a2e7db036a352a7582cea24811ef Mon Sep 17 00:00:00 2001 From: "Patrick J. McNerthney" Date: Tue, 27 Jan 2026 12:35:20 -1000 Subject: [PATCH] Update network backend examples to use httpcore.MackBackend --- docs/advanced/transports.md | 9 +++++---- httpx/_transports/default.py | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/advanced/transports.md b/docs/advanced/transports.md index aff14f96..c3a53ee7 100644 --- a/docs/advanced/transports.md +++ b/docs/advanced/transports.md @@ -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 diff --git a/httpx/_transports/default.py b/httpx/_transports/default.py index e203998e..ba40956e 100644 --- a/httpx/_transports/default.py +++ b/httpx/_transports/default.py @@ -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