From: Daniel Sheppard Date: 2005-09-29T10:12:50+09:00 Subject: Re: Complicated Proxy Configurations ------_=_NextPart_001_01C5C492.9B588F0E Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Eeep. wrong file. The attached one is the one that actually works.=20 -----Original Message----- From: Daniel Sheppard=20 Sent: Thursday, 29 September 2005 10:13 AM To: ruby-talk ML Subject: Complicated Proxy Configurations 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 =09when "localhost", =09 "127.0.0.1", =09 "192.168.0.2", =09 "168.168.8.88", =09 /^172\.17\./ =09 nil =09when "www.example.com" =09 "http://proxy1:5466" =09else =09 "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? ######################################################################## ############# This email has been scanned by MailMarshal, an email content filter. ######################################################################## ############# #########################################################################= ############ This email has been scanned by MailMarshal, an email content filter. #########################################################################= ############ ------_=_NextPart_001_01C5C492.9B588F0E Content-Type: application/octet-stream; name="fix_proxy.rb" Content-Transfer-Encoding: base64 Content-Description: fix_proxy.rb Content-Disposition: attachment; filename="fix_proxy.rb" cmVxdWlyZSAnbmV0L2h0dHAnDQoNCm1vZHVsZSBOZXQNCiAgICBjbGFzcyA8PCBIVFRQCiAgICAg ICMgQ3JlYXRlcyBhIG5ldyBOZXQ6OkhUVFAgb2JqZWN0LgogICAgIC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