# HG changeset patch # User mpm@selenic.com # Date 1118642708 28800 # Node ID 73b8a8a059eca41d4365b2741b5cfaabd86c2d3c # Parent 292e10b5831ae2d903b57bd1d949349fb182ed6b Transparent proxy support -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Transparent proxy support Originally from "Michael S. Tsirkin" manifest hash: 74cf7456ef35ff8d4c007544f0d1a57c69d3c929 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCrSIUywK+sNU5EO8RAje1AJ41ALW8soF78Mo3UTraV1QQvJoFSQCgrqvc I9ohlI4hzdjOD+wSwRGlERQ= =Ugfi -----END PGP SIGNATURE----- diff -r 292e10b5831a -r 73b8a8a059ec doc/hg.1.txt --- a/doc/hg.1.txt Sun Jun 12 20:39:08 2005 -0800 +++ b/doc/hg.1.txt Sun Jun 12 22:05:08 2005 -0800 @@ -188,6 +188,22 @@ (which could be a local path or a remote URI), the format is with each mapping on a seperate line +NON_TRANSPARENT PROXY SUPPORT +----- + + To access a mercurial repository through a proxy, + create a file $HOME/.hgrc in the following format: + +[http_proxy] +host=myproxy:8080 +user= +passwd= +no=,,,... + + "user","passwd" fields are used for authenticating proxies, + "no" is a comma-separated list of local host names + for which proxy must be bypassed. + BUGS ---- Probably lots, please post them to the mailing list (See Resources below) diff -r 292e10b5831a -r 73b8a8a059ec mercurial/hg.py --- a/mercurial/hg.py Sun Jun 12 20:39:08 2005 -0800 +++ b/mercurial/hg.py Sun Jun 12 22:05:08 2005 -0800 @@ -1228,6 +1228,36 @@ def __init__(self, ui, path): self.url = path self.ui = ui + no_list = [ "localhost", "127.0.0.1" ] + host = ui.config("http_proxy", "host") + user = ui.config("http_proxy", "user") + passwd = ui.config("http_proxy", "passwd") + no = ui.config("http_proxy", "no") + if no: + no_list = no_list + no.split(",") + + no_proxy = 0 + for h in no_list: + if (path.startswith("http://" + h + "/") or + path.startswith("http://" + h + ":") or + path == "http://" + h): + no_proxy = 1 + + # Note: urllib2 takes proxy values from the environment and those will + # take precedence + + proxy_handler = urllib2.BaseHandler() + if host and not no_proxy: + proxy_handler = urllib2.ProxyHandler({"http" : "http://" + host}) + + authinfo = None + if user and passwd: + passmgr = urllib2.HTTPPasswordMgrWithDefaultRealm() + passmgr.add_password(None, host, user, passwd) + authinfo = urllib2.ProxyBasicAuthHandler(passmgr) + + opener = urllib2.build_opener(proxy_handler, authinfo) + urllib2.install_opener(opener) def do_cmd(self, cmd, **args): self.ui.debug("sending %s command\n" % cmd) @@ -1235,7 +1265,7 @@ q.update(args) qs = urllib.urlencode(q) cu = "%s?%s" % (self.url, qs) - return urllib.urlopen(cu) + return urllib2.urlopen(cu) def heads(self): d = self.do_cmd("heads").read()