I was looking to solve the same problem. I was concerned about forward the compatibility of the "exquisitely ugly incantation" provided in the answer here. I'm using httpx with Trio, and realized I can use the Trio socket implementation to use an async version of sockets to answer this question. see: https://trio.readthedocs.io/en/stable/reference-io.html#trio.socket.getaddrinfo
I posted this question to the httpx Q&A and got this answer: https://github.com/encode/httpx/discussions/2633#discussioncomment-5439764 In short, access to this information is provided through httpcore. There is an open issue to update the documentation.
import httpx with httpx.Client() as client: with client.stream("GET", "https://httpbin.org/get") as response: network_stream = response.extensions["network_stream"] server_addr = network_stream.get_extra_info("server_addr") print(response.json()) print(server_addr) read: https://www.encode.io/httpcore/extensions/#extra-network-information