I am working with a ruby application that uses some loosely coupled
modules that interface with a web service. These modules use net::http
module of ruby for network communication. But the original code has no
means to specify proxy configurations. And of course ruby’s net::http
does not respect system proxy configuration.
I would like to know if there is a way to channelize all the http
requests through the proxy server specified by path variable
‘http_proxy’ without changing these modules. (These modules are
separately maintained and making hard changes would make things
difficult while updating them in future)
Any help would be appreciated.
[…]
And of course ruby’s net::http
does not respect system proxy configuration.
You can make it respect the system proxy configuration:
require ‘net/http’
proxy_uri = URI.parse(ENV[‘http_proxy’])
proxy_class = Net::HTTP::Proxy(proxy.host, proxy.port)
proxy_class.start(‘www.example.com’) do |http|
# whatever
end
I would like to know if there is a way to channelize all the http
requests through the proxy server specified by path variable
‘http_proxy’ without changing these modules. (These modules are
separately maintained and making hard changes would make things
difficult while updating them in future)
So you can probably channelize all your http requests through the
proxy_class.
require ‘net/http’
proxy_uri = URI.parse(ENV[‘http_proxy’])
proxy_class = Net::HTTP::Proxy(proxy.host, proxy.port)
I meant,
proxy_class = Net::HTTP::Proxy(proxy_url.host, proxy_url.port)
I’ve been working on a gem that lets you force TCPSocket to use a proxy.
I haven’t pushed it to rubygems yet but you can clone my repo and
install it
and try it out.
https://github.com/samuelkadolph/ruby-proxifier
On Tue, Jul 19, 2011 at 2:30 AM, Anurag P.
[email protected]wrote:
http://about.me/yeban/
–
*Samuel K.
*E [email protected]
@Anurag
Thank you for your answer. I really didnt expect you to post a reply.
What you are suggesting is definitely the standard way to use a proxy in
net::http with the proxy configuration being retrieved from the
environment variables
But as you see, in your code :
proxy_class.start(‘www.example.com’) do |http|
# whatever
end
I do not always have the url to which the request is being POSTed. In
fact the request is already being made by the third party code using
something like :
res = Net::HTTP.start(url.host, url.port) {|http|
# whatever
}
So what I really meant was that if I could force this request to follow
the proxy configurations without changing the code.
rake install works for me in 1.9.2 and 1.8.7. It does use bundler so you
have to have that gem installed.
If that’s not the case would you mind posting the output to
http://pastie.org/ so I can look at it?
Thanks.
On Wed, Jul 20, 2011 at 8:20 AM, eunikorn imazinator
[email protected]wrote:
@samuelkadolph
Thank you for your fantastic contribution.
Although the rake install failed for me (could it be a version issue ? )
I could build the gem and install it .
Works like a charm. Thank you again.
–
Posted via http://www.ruby-forum.com/.
–
*Samuel K.
*E [email protected]
@samuelkadolph
Thank you for your fantastic contribution.
Although the rake install failed for me (could it be a version issue ? )
I could build the gem and install it .
Works like a charm. Thank you again.