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?
- lib/net/http.rb (Net::HTTP#connect): use local_host and local_port if specified. patched by Ricardo Amorim [Feature #6617]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36367 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Updated by drbrain (Eric Hodel) almost 7 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.
Updated by mksm (Ricardo Amorim) almost 7 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.
Updated by mksm (Ricardo Amorim) over 6 years ago
Updated by naruse (Yui NARUSE) over 6 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100