I posted this on the mousehole-scripters list, but thought it might be
useful to non-mousehole rubyists (or mousehole users that aren't on the
mailing list).
I work in a corporate environment, and occasionally have to use either a
second proxy or no proxy depending on the hostname. In order to
configure the proxy that ruby uses, you can set the http_proxy
environment variable, but that's insufficient for my needs. So I added
in a little fragment (attached) which allows me to have a separate
configuration file that defines which proxy to use for a given host.
Require this directly after/instead of requiring net/http, and you can
put a proxy_config.rb file in your current directory that will be eval'd
constantly to determine what proxy to use for the given host. It gets
the host passed in, so you can write a file something like this:
case host
when "localhost",
"127.0.0.1",
"192.168.0.2",
"168.168.8.88",
/^172\.17\./
nil
when "www.example.com"
"http://proxy1:5466"
else
"http://proxy2:8080"
end
It doesn’t deal with proxy authentication at all, but some minor changes
would fix that. If you want authentication, pass back the username and
password as well (ie, [“http://proxy1:5466”,“monkey”,“magic”]
Also, has anybody done any work towards allowing NTLM authentication
under ruby? Or do I have to continue using
http://apserver.sourceforge.net/ to provide a local proxy that runs the
NTLM part of the puzzle?
fix_proxy.rb (869 Bytes)
···
#####################################################################################
This email has been scanned by MailMarshal, an email content filter.
#####################################################################################