~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Pool
  • Date: 2010-04-01 04:41:18 UTC
  • mto: This revision was merged to the branch mainline in revision 5128.
  • Revision ID: mbp@sourcefrog.net-20100401044118-shyctqc02ob08ngz
ignore .testrepository

Show diffs side-by-side

added added

removed removed

Lines of Context:
378
378
            port = conn_class.default_port
379
379
        self.proxied_host = '%s:%s' % (host, port)
380
380
        urllib2.Request.set_proxy(self, proxy, type)
381
 
        # When urllib2 makes a https request with our wrapper code and a proxy,
382
 
        # it sets Host to the https proxy, not the host we want to talk to.
383
 
        # I'm fairly sure this is our fault, but what is the cause is an open
384
 
        # question. -- Robert Collins May 8 2010.
385
 
        self.add_unredirected_header('Host', self.proxied_host)
386
381
 
387
382
 
388
383
class _ConnectRequest(Request):
716
711
            connect = _ConnectRequest(request)
717
712
            response = self.parent.open(connect)
718
713
            if response.code != 200:
719
 
                raise errors.ConnectionError("Can't connect to %s via proxy %s" % (
 
714
                raise ConnectionError("Can't connect to %s via proxy %s" % (
720
715
                        connect.proxied_host, self.host))
721
716
            # Housekeeping
722
717
            connection.cleanup_pipe()
873
868
                print 'Will unbind %s_open for %r' % (type, proxy)
874
869
            delattr(self, '%s_open' % type)
875
870
 
876
 
        def bind_scheme_request(proxy, scheme):
877
 
            if proxy is None:
878
 
                return
879
 
            scheme_request = scheme + '_request'
880
 
            if self._debuglevel >= 3:
881
 
                print 'Will bind %s for %r' % (scheme_request, proxy)
882
 
            setattr(self, scheme_request,
883
 
                lambda request: self.set_proxy(request, scheme))
884
871
        # We are interested only by the http[s] proxies
885
872
        http_proxy = self.get_proxy_env_var('http')
886
 
        bind_scheme_request(http_proxy, 'http')
887
873
        https_proxy = self.get_proxy_env_var('https')
888
 
        bind_scheme_request(https_proxy, 'https')
 
874
 
 
875
        if http_proxy is not None:
 
876
            if self._debuglevel >= 3:
 
877
                print 'Will bind http_request for %r' % http_proxy
 
878
            setattr(self, 'http_request',
 
879
                    lambda request: self.set_proxy(request, 'http'))
 
880
 
 
881
        if https_proxy is not None:
 
882
            if self._debuglevel >= 3:
 
883
                print 'Will bind http_request for %r' % https_proxy
 
884
            setattr(self, 'https_request',
 
885
                    lambda request: self.set_proxy(request, 'https'))
889
886
 
890
887
    def get_proxy_env_var(self, name, default_to='all'):
891
888
        """Get a proxy env var.