ureq icon indicating copy to clipboard operation
ureq copied to clipboard

Suggestion: add `Response::remote_addr()` method

Open mvforell opened this issue 2 years ago • 2 comments

It would be great if ureq::Response had a remote_addr() method that returns an Option<SocketAddr> describing the remote address that the response came from.

E.g. reqwest's Response type already has such a method.

What do you think about this?

mvforell avatar Mar 04 '22 23:03 mvforell

I've taken a glance at the code for ureq::Response, and getting the remote address could be achieved by adding this line:

let remote_addr = stream.socket().and_then(|s| s.peer_addr().ok());

at the start of Response::do_from_stream() and storing that in a new member of Response (and adding a getter for that, of course).

But I'm not sure if that's acceptable for you, as this means an increased size for Response.

mvforell avatar Mar 04 '22 23:03 mvforell

An IP address is quite small. I'd be fine with adding that to response.

Happy to accept a PR for this.

algesten avatar Mar 05 '22 07:03 algesten