require 'open-uri' require 'webrick/httpproxy' #ProxyStruct = Struct.new(:host, :port, :userinfo) def lookup_proxy(host) unless($proxy_last_update && $proxy_last_update == File.mtime("proxy_config.rb")) $proxy_last_update = File.mtime("proxy_config.rb") $proxy_proc = File.readlines("proxy_config.rb").join("\n") end if File.exist?("proxy_config.rb") proxy = eval($proxy_proc) return URI.parse(proxy) if proxy end class URI::Generic def find_proxy #~ proxy = lookup_proxy(host) #~ return URI.parse("http://#{proxy.host}:#{proxy.port}") if proxy lookup_proxy(host) end end class WEBrick::HTTPProxyServer def proxy_uri(req,res) lookup_proxy(req.host) #~ lookup_proxy(req.host) end end