Merge lp:~spiv/bzr/xmlrpc-proxy-558343-2.1 into lp:bzr/2.1

Proposed by Andrew Bennetts
Status: Merged
Approved by: Vincent Ladeuil
Approved revision: no longer in the source branch.
Merged at revision: 4866
Proposed branch: lp:~spiv/bzr/xmlrpc-proxy-558343-2.1
Merge into: lp:bzr/2.1
Diff against target: 70 lines (+19/-13)
2 files modified
NEWS (+3/-0)
bzrlib/transport/http/_urllib2_wrappers.py (+16/-13)
To merge this branch: bzr merge lp:~spiv/bzr/xmlrpc-proxy-558343-2.1
Reviewer Review Type Date Requested Status
Vincent Ladeuil Approve
Review via email: mp+36679@code.launchpad.net

Commit message

Fix lp: urls behind an https proxy. (#558343)

Description of the change

This is just a backport of Robert's fix for bug 558343 to the 2.1 branch. It seems simple and safe enough, and has been in trunk since 2.2b3, so is presumably well-tested in practice.

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

Makes sense.

review: Approve
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'NEWS'
2--- NEWS 2010-09-26 21:35:58 +0000
3+++ NEWS 2010-09-27 06:14:58 +0000
4@@ -26,6 +26,9 @@
5 * Skip the tests that requires respecting the chmod bits when running as root.
6 (Vincent Ladeuil, #646133)
7
8+* Using bzr with `lp:` urls behind an http proxy should work.
9+ (Robert Collins, #558343)
10+
11 Improvements
12 ************
13
14
15=== modified file 'bzrlib/transport/http/_urllib2_wrappers.py'
16--- bzrlib/transport/http/_urllib2_wrappers.py 2010-02-17 17:11:16 +0000
17+++ bzrlib/transport/http/_urllib2_wrappers.py 2010-09-27 06:14:58 +0000
18@@ -378,6 +378,11 @@
19 port = conn_class.default_port
20 self.proxied_host = '%s:%s' % (host, port)
21 urllib2.Request.set_proxy(self, proxy, type)
22+ # When urllib2 makes a https request with our wrapper code and a proxy,
23+ # it sets Host to the https proxy, not the host we want to talk to.
24+ # I'm fairly sure this is our fault, but what is the cause is an open
25+ # question. -- Robert Collins May 8 2010.
26+ self.add_unredirected_header('Host', self.proxied_host)
27
28
29 class _ConnectRequest(Request):
30@@ -711,7 +716,7 @@
31 connect = _ConnectRequest(request)
32 response = self.parent.open(connect)
33 if response.code != 200:
34- raise ConnectionError("Can't connect to %s via proxy %s" % (
35+ raise errors.ConnectionError("Can't connect to %s via proxy %s" % (
36 connect.proxied_host, self.host))
37 # Housekeeping
38 connection.cleanup_pipe()
39@@ -868,21 +873,19 @@
40 print 'Will unbind %s_open for %r' % (type, proxy)
41 delattr(self, '%s_open' % type)
42
43+ def bind_scheme_request(proxy, scheme):
44+ if proxy is None:
45+ return
46+ scheme_request = scheme + '_request'
47+ if self._debuglevel >= 3:
48+ print 'Will bind %s for %r' % (scheme_request, proxy)
49+ setattr(self, scheme_request,
50+ lambda request: self.set_proxy(request, scheme))
51 # We are interested only by the http[s] proxies
52 http_proxy = self.get_proxy_env_var('http')
53+ bind_scheme_request(http_proxy, 'http')
54 https_proxy = self.get_proxy_env_var('https')
55-
56- if http_proxy is not None:
57- if self._debuglevel >= 3:
58- print 'Will bind http_request for %r' % http_proxy
59- setattr(self, 'http_request',
60- lambda request: self.set_proxy(request, 'http'))
61-
62- if https_proxy is not None:
63- if self._debuglevel >= 3:
64- print 'Will bind http_request for %r' % https_proxy
65- setattr(self, 'https_request',
66- lambda request: self.set_proxy(request, 'https'))
67+ bind_scheme_request(https_proxy, 'https')
68
69 def get_proxy_env_var(self, name, default_to='all'):
70 """Get a proxy env var.

Subscribers

People subscribed via source and target branches