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?
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.
This issue was solved with changeset r36367.
Ricardo, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
lib/net/http.rb (Net::HTTP#connect): use local_host and local_port
if specified. patched by Ricardo Amorim [Feature #6617]