Skip to content

Commit

Permalink
Correctly set Host header when using a proxy
Browse files Browse the repository at this point in the history
Fixed a bug in _set_proxy_headers that ignores the port when setting the
'Host' HTTP header while a proxy is used.
  • Loading branch information
gavrie authored and Gavrie Philipson committed Jul 29, 2013
1 parent 3e0e50c commit d89d508
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions test/test_proxymanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ def test_proxy_headers(self):

self.assertEqual(headers, provided_headers)

# Verify proxy with nonstandard port
provided_headers = {'Accept': 'application/json'}
expected_headers = provided_headers.copy()
expected_headers.update({'Host': 'pypi.python.org:8080'})
url_with_port = 'http://pypi.python.org:8080/test'
headers = p._set_proxy_headers(url_with_port, provided_headers)

self.assertEqual(headers, expected_headers)

if __name__ == '__main__':
unittest.main()
6 changes: 3 additions & 3 deletions urllib3/poolmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,9 +181,9 @@ def _set_proxy_headers(self, url, headers=None):
"""
headers_ = {'Accept': '*/*'}

host = parse_url(url).host
if host:
headers_['Host'] = host
netloc = parse_url(url).netloc
if netloc:
headers_['Host'] = netloc

if headers:
headers_.update(headers)
Expand Down

3 comments on commit d89d508

@schlamar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shazow
Copy link
Member

@shazow shazow commented on d89d508 Jul 31, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yessir, you can pull this change (already merged).

@schlamar
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, perfect. I already dropped the latter one before rebasing against master :)

Please sign in to comment.