Replies: 2 comments
-
|
httpx version: 0.25.0 |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Currently there is no support for import httpx
class NameSolver(dict):
def resolve(self, request: httpx.Request) -> httpx.Request:
host = request.url.host
ip = self.get(host)
if ip:
request.extensions["sni_hostname"] = host
request.url = request.url.copy_with(host=ip)
return request
class CustomHost(httpx.HTTPTransport):
def __init__(self, solver: NameSolver, *args, **kwargs) -> None:
self.solver = solver
super().__init__(*args, **kwargs)
def handle_request(self, request: httpx.Request) -> httpx.Response:
request = self.solver.resolve(request)
return super().handle_request(request)Use it as: ns = NameSolver({"crawl_api": "127.0.0.1"}) # or load `hosts` file content here
with httpx.Client(transport=CustomHost(ns)) as client:
r = client.get("http://crawl_api:8000/") |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
The domain crawl_api is set in /etc/hosts as
127.0.0.1 crawl_api
I can open it with "requests". But not with "httpx".
Beta Was this translation helpful? Give feedback.
All reactions