Is there a way to attach Ruby Net::HTTP request to a specific IP address / network interface?

I know this is old, but hopefully someone else finds this useful, as I needed this today. You can do the following:

http = Net::HTTP.new(uri.host, uri.port)
http.local_host = ip
response = http.request(request)

Note that you I don't believe you can use Net::HTTP.start, as it doesn't accept local_host as an option.


There is in fact a way to do this if you monkey patch TCPSocket:

https://gist.github.com/800214

Curb is awesome but won't work with Jruby so I've been looking into alternatives...