Net::HTTP: Bind to a specific local IP/port
Despite having several solutions floating around the net, this feature is currently not present in Net::HTTP. I searched the issues but didn't find any discussion on this. How does the dev team feel about this? Can I submit a patch for revision?
#1 [ruby-core:45764] Updated by drbrain (Eric Hodel) about 5 years ago
- Category set to lib
Bind to a local port like TCPSocket.new does? I'm sure this feature could be added.
I think the easiest way to add it would result in an API like:
http = Net::HTTP.new remote_host
http.local_host = local_host
Instead of passing the local host and port as parameters to Net::HTTP.new or Net::HTTP.start.
#2 [ruby-core:45773] Updated by mksm (Ricardo Amorim) about 5 years ago
I agree. You can pass both local_ip and local_port to TCPSocket.open in Net::HTTP#connect.
Having the setter exposed would allow the user to change the local IP address between connections. Any ideas if this could cause problems with Net::HTTP or remote servers? There's also proxy and ipv6 support, both which I have never tested using this approach.
#8 [ruby-core:46195] Updated by mksm (Ricardo Amorim) about 5 years ago
#10 Updated by naruse (Yui NARUSE) about 5 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100