cli icon indicating copy to clipboard operation
cli copied to clipboard

Display used server IP in verbose mode

Open SRv6d opened this issue 2 years ago • 5 comments

Checklist

  • [X] 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.

SRv6d avatar Apr 06 '23 22:04 SRv6d

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

turingnixstyx avatar Apr 22 '23 08:04 turingnixstyx

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).

SRv6d avatar Apr 22 '23 15:04 SRv6d

@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 avatar Aug 19 '23 16:08 lucasconnellm

@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.

SRv6d avatar Aug 21 '23 20:08 SRv6d

Somewhat partial solution would be to at least include the IP which httpie connected to (as opposed to listing all the attempted IP addresses). This should be easy enough. Threw some code into client.py (I realize this is not where the output should happen, just a POC) and this is how the output looks like:

$ python -m httpie https://storage.googleapis.com/generate_204
Connected to storage.googleapis.com (199.36.153.7) on port 443

HTTP/1.1 204 No Content
Content-Length: 0
Cross-Origin-Resource-Policy: cross-origin
Date: Sat, 30 Dec 2023 00:49:08 GMT

jabbson avatar Dec 30 '23 01:12 jabbson