Allow for developer/commandline control of name resolution #2072
-
I don't think httpx must create any new functionality but I think it will eventually choose to make users/developers lives the below gist has this commentary and code (including a main that exercises the code using httpbin.org service ip addreses) https://gist.github.com/toppk/a5838c9727d806c7845f7be0e2eacf2f There are two crazy things here, what I am doing and why. First the why:There is a need to distinguish name resolution from a traditional http
There are a couple of notable DNS outages where there was significant
A well implement Service Discovery layer generally addresses a bunch of these Here is an implementation to add this capability. This is the how:Creating a custom Transport was the basis for the implementation, which operates
My thoughtsuse casesI do think that a proper service discovery capability would be built as a separate I think the caching/dns outages resiliency is an obvious need, and there are examples Finally having a separate hostname used in http/tls layer from hostname used for implementationI think providing a developer defined lookup that could be plumbed into the appropriate
Another option would be to plumb a separate hostname inside httpcore's origin, which Additionally since the connection will be maintained inside the pool, there is a These pool lifecycle tricks are really for the poor mans service discovery, and prior arturllib3 suggests using a special connection pool, which is an interesting solution. I was thinking of a special proxy as an alternative implementation. For my requests/urllib3 needs, I chose the monkey patch route (urllib3.util.connection.create_connection) https://urllib3.readthedocs.io/en/latest/advanced-usage.html#custom-sni-hostname curl has two methods to change host that I connect to vs hostname that I use inside http/tls curl --connect-to --resolve okhttp user provided lookup implementation: https://square.github.io/okhttp/4.x/okhttp/okhttp3/-dns/ some random obligatory semi useless SE link: https://serverfault.com/questions/327708/how-browsers-handle-multiple-ips |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
Great question! As it happens # This will connect to 1.2.3.4 but using the `www.example.com` header,
# *but* the sni hostname will also be 1.2.3.4 which isn't what we wanted.
$ httpx https://1.2.3.4 --header Host www.example.com I think we've got space for two different request extensions here... r = httpx.get("https://www.example.com", extensions={"connect_to": ...}) r = httpx.get("https://www.example.com", extensions={"sni_hostname": ...}) We'd then probably want to expose these to the command line client in a way that maps obviously onto the programmatic API. Perhaps this... $ httpx https://www.example.com --x-connect-to ... $ httpx https://www.example.com --x-sni-hostname ... At some point I would also like to see |
Beta Was this translation helpful? Give feedback.
Great question!
As it happens
httpx
andhttpcore
do currently allow you to connect to a different IP than is used in theHost:
header, but that's not a lot of use on it's own, because, eg...I think we've got space for two different request extensions here...
We'd then probably want to expose these to the command line client in a way that maps obvi…