httpie/cli

Display used server IP in verbose mode

SRv6d opened this issue · 5 comments

SRv6d commented

Checklist

  • I've searched for similar feature requests.

Enhancement request

When running curl in verbose mode, it will print every ip it tries to connect to, until a connection is stablished.

~ ➜ curl -v www.google.com       
*   Trying [2001:db8::3:8bd0]:80...
*   Trying [2001:db8::3:8bd1]:80...
* Connected to www.google.com (2001:db8::3:8bd1) port 80 (#0)
> GET / HTTP/1.1

The above example request tells the user that curl was trying to connect to both 2001:db8::3:8bd0 and 2001:db8::3:8bd1, while ultimately a connection was established to 2001:db8::3:8bd1.

While ideally httpie would implement the same output as curl, it should at least be able to print the IP it connected to.


Problem it solves

It is very common to have multiple IPv4 and IPv6 addresses within DNS and which one exactly was used is very relevant when debugging or in cases where different ip's may return different content.

Hey @SRv6d, I am a newbie to Open-source, can I pick this up?

SRv6d commented

Hey @SRv6d, I am a newbie to Open-source, can I pick this up?

Of course you can, although your PR would have to be approved by a httpie maintainer (which I am not).

@turingnixstyx Any updates on this? I played around with it for a bit this morning, and it's not as easy as it looks on the surface.

All of the low level http requests are being handled by requests which in turn uses urllib3. Neither of these provide this information while attempting the connection (not even as debug logs we could try to capture and rewrite). I got a PoC working locally where we can access the IP of the successful connection, but it uses undocumented APIs and is not compatible across Python/requests versions (so I don't think that's viable either).

The only robust solution would be to implement the get_connection function in HTTPie's adapter to return a custom urllib3.ConnectionPool which does expose this information. This would be very involved and way out of my wheelhouse. Perhaps somebody smarter could figure it out :p


@SRv6d If you're still in search of a solution, I found https://github.com/httptoolkit/httptoolkit while poking around. It's open source and would allow you to open a shell which sends all of its traffic through a local proxy capturing all the connection attempts. ⚠️ I have not used it or inspected the source code; I cannot vouch for or endorse it in any way. ⚠️ But it does look like it could do some of what you want.

@lucasconnellm Appreciate the tip, but with the lack of basic features like IP in verbose mode, HTTP/2 let alone HTTP/3, I've gone back to curl. httpx provides nicer UX but is not useful to me as a professional tool.