Skip to content

Commit d4e402c

Browse files
committed
Fix python interception for http.client requests with inline ports
Previously, calling http.client.HTTPConnection('example.com', 80) worked fine, but http.client.HTTPConnection('example.com:80') failed because that string was used directly as the host, with the default 80 set as the port separately in our override. The override now delegates handling this back to Python itself, to ensure that works correctly. Most users aren't doing this directly anyway, and libraries typically call low-level HTTP methods with the full port automatically, but it can fail in some real-world cases.
1 parent 3f45ee4 commit d4e402c

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

overrides/pythonpath/http/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Redirect and then tunnel all plain HTTP connections:
1717
_http_connection_init = HTTPConnection.__init__
1818
@functools.wraps(_http_connection_init)
19-
def _new_http_connection_init(self, host, port=80, *k, **kw):
19+
def _new_http_connection_init(self, host, port=None, *k, **kw):
2020
_http_connection_init(self, _proxyHost, int(_proxyPort), *k, **kw)
2121
self.set_tunnel(host, port)
2222
HTTPConnection.__init__ = _new_http_connection_init
@@ -31,7 +31,7 @@ def _build_default_context():
3131
# Redirect & tunnel HTTPS connections, and inject our CA certificate:
3232
_https_connection_init = HTTPSConnection.__init__
3333
@functools.wraps(_https_connection_init)
34-
def _new_https_connection_init(self, host, port=443, *k, **kw):
34+
def _new_https_connection_init(self, host, port=None, *k, **kw):
3535
context = None
3636
if 'context' in kw:
3737
context = kw.get('context')

overrides/pythonpath/httplib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# Redirect and then tunnel all plain HTTP connections:
1717
_http_connection_init = HTTPConnection.__init__
1818
@functools.wraps(_http_connection_init)
19-
def _new_http_connection_init(self, host, port=80, *k, **kw):
19+
def _new_http_connection_init(self, host, port=None, *k, **kw):
2020
_http_connection_init(self, _proxyHost, _proxyPort, *k, **kw)
2121
self.set_tunnel(host, port)
2222
HTTPConnection.__init__ = _new_http_connection_init
@@ -31,7 +31,7 @@ def _build_default_context():
3131
# Redirect & tunnel HTTPS connections, and inject our CA certificate:
3232
_https_connection_init = HTTPSConnection.__init__
3333
@functools.wraps(_https_connection_init)
34-
def _new_https_connection_init(self, host, port=443, *k, **kw):
34+
def _new_https_connection_init(self, host, port=None, *k, **kw):
3535
context = None
3636
if 'context' in kw:
3737
context = kw.get('context')

0 commit comments

Comments
 (0)