/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/_urllib2_wrappers.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-12-11 13:24:55 UTC
  • mto: (2182.1.1 Aaron's integration)
  • mto: This revision was merged to the branch mainline in revision 2183.
  • Revision ID: v.ladeuil+lp@free.fr-20061211132455-e8k81db8ktfwvrlz
Tests for proxies, covering  #74759.

* bzrlib/transport/http/_urllib2_wrappers.py:
(ProxyHandler.proxy_bypass): Matches against the modified regexp,
not the original domain.

* bzrlib/tests/test_http.py:
(TestProxyHttpServer, TestProxyHttpServer_urllib,
TestProxyHttpServer_pycurl): New classes for proxy tests.

* bzrlib/tests/HttpServer.py:
(HttpServer._http_start): Give access to the port used by the
server socket.
(HttpServer.setUp, HttpServer.tearDown): Handles the 'no_proxy'
env var too.

* bzrlib/tests/HTTPTestUtil.py:
(TestCaseWithTwoWebservers): New class for tests needing two
related web servers.
(FakeProxyRequestHandler): New class to fake a proxy http server.

Show diffs side-by-side

added added

removed removed

Lines of Context:
662
662
 
663
663
    def proxy_bypass(self, host):
664
664
        """Check if host should be proxied or not"""
665
 
        if self._debuglevel > 0:
666
 
            print 'Is [%r] proxied or not' % host
667
665
        no_proxy = self.get_proxy('no')
668
666
        if no_proxy is None:
669
667
            return False
670
668
        hhost, hport = urllib.splitport(host)
671
 
        if self._debuglevel > 0:
672
 
            print 'hhost [%r], hport [%r]' % (hhost, hport)
673
669
        # Does host match any of the domains mentionned in
674
670
        # no_proxy The rules about what is authorized in no_proxy
675
671
        # are fuzzy (too say the least). We try to allows most
676
672
        # commonly seen values.
677
673
        for domain in no_proxy.split(','):
678
674
            dhost, dport = urllib.splitport(domain)
679
 
            if self._debuglevel > 0:
680
 
                print 'dhost [%r], dport [%r]' % (hhost, hport)
681
 
            if hport == dport:
 
675
            if hport == dport or dport is None:
682
676
                # Protect glob chars
683
677
                dhost = dhost.replace(".", r"\.")
684
678
                dhost = dhost.replace("*", r".*")
685
679
                dhost = dhost.replace("?", r".")
686
 
                if re.match(domain, hhost, re.IGNORECASE):
 
680
                if re.match(dhost, hhost, re.IGNORECASE):
687
681
                    return True
688
682
        # Nevertheless, there are platform specific ways to
689
683
        # ignore proxies...