Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Add an additional method on Response that allows you to see the resolved IP of the Response #1186

Open
BobbyMcWho opened this issue Oct 7, 2020 · 6 comments
Labels

Comments

@BobbyMcWho
Copy link
Contributor

I've done some fairly comprehensive digging into the source code of this gem, typhoeus, and net::http, and I believe this should be something we can implement.

I would like to be able to access the resolved IP of the request on the response body, Net::HTTP I believe exposes this via #ipaddr, and Typhoeus via Response::Informations#primary_ip.

I believe this would involve adding the method to the Faraday::Response class similar to body, adding an ip attr to the Env class, and in each adapter changing the save_response call to also add the ip info to the env.

@iMacTia
Copy link
Member

iMacTia commented Oct 7, 2020

@BobbyMcWho sounds useful and I don't think this is currently available in Faraday.
I checked the PRs history and I found a similar addition done for reason_phrase: #547.
I'm not a huge fan of the implementation, but I doubt there's an easier/better way to implement this, so it could be used as a reference for implementing this as well.

Just a list of "requirements":

  1. The change should be fully backwards-compatible (careful about Options definition, as the order of fields does matter)
  2. Appreciate this is a pain, but the implementation should be attempted for ALL adapters, not just Net::HTTP and Typhoeus. If an adapter is skipped it should be because it does not allow to fetch that info at all.
  3. I don't have strong feelings for the name of the new field, but I noticed Net::HTTP and Typhoeus already call it in a different way. It would be nice to find a technical reference for it and use that

@iMacTia iMacTia added the feature label Oct 7, 2020
@BobbyMcWho
Copy link
Contributor Author

@iMacTia how do you feel about peer_ip ?

@iMacTia
Copy link
Member

iMacTia commented Oct 8, 2020

@BobbyMcWho that would work, I was thinking also of resolved_ip or some other reference to DNS, but as I mentioned I don't feel too strongly as far as it's a recognised technical term

@BobbyMcWho
Copy link
Contributor Author

Yeah I started digging into this last night and there doesn't seem to be broad support for it in the http libraries, even Net::Http is a bit more of a challenge than I expected. I'll have to do some more digging when I have some time

@raldred
Copy link

raldred commented May 3, 2023

I know this request is a bit stale, but knowing the host ip address would be super useful for us, to trace connections.
NET::HTTP provides ipaddr which will return the underlying sockets peer address as already mentioned
https://ruby-doc.org/stdlib-3.0.0/libdoc/net/http/rdoc/Net/HTTP.html#method-i-ipaddr

@BobbyMcWho
Copy link
Contributor Author

I unfortunately don't have time to work on this, so if you want to pick up the mantle, I'm sure others will want it later as well 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants