Skip to content

Commit 1c266ba

Browse files
committed
Fix interception for Python's httplib2
Previously, this failed because a) our http.client interception left the port as a string, which failed some internal validation, and b) it didn't trust the certificate through any normal mechanism.
1 parent 03f21f5 commit 1c266ba

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

overrides/pythonpath/http/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
_http_connection_init = HTTPConnection.__init__
1818
@functools.wraps(_http_connection_init)
1919
def _new_http_connection_init(self, host, port=80, *k, **kw):
20-
_http_connection_init(self, _proxyHost, _proxyPort, *k, **kw)
20+
_http_connection_init(self, _proxyHost, int(_proxyPort), *k, **kw)
2121
self.set_tunnel(host, port)
2222
HTTPConnection.__init__ = _new_http_connection_init
2323

@@ -43,6 +43,6 @@ def _new_https_connection_init(self, host, port=443, *k, **kw):
4343

4444
context.load_verify_locations(_certPath)
4545

46-
_https_connection_init(self, _proxyHost, _proxyPort, *k, **kw)
46+
_https_connection_init(self, _proxyHost, int(_proxyPort), *k, **kw)
4747
self.set_tunnel(host, port)
4848
HTTPSConnection.__init__ = _new_https_connection_init

overrides/pythonpath/httplib2.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from httptoolkit_intercept import preload_real_module
2+
3+
preload_real_module('httplib2')
4+
5+
import httplib2, os, functools
6+
7+
# Re-export all public fields
8+
from httplib2 import *
9+
# Load a few extra notable private fields, for max compatibility
10+
from httplib2 import __file__, __doc__
11+
12+
_certPath = os.environ['SSL_CERT_FILE']
13+
14+
# Ensure all connections trust our cert:
15+
_http_init = httplib2.Http.__init__
16+
@functools.wraps(_http_init)
17+
def _new_http_init(self, *k, **kw):
18+
kList = list(k)
19+
if len(kList) > 3:
20+
kList[3] = _certPath
21+
else:
22+
kw['ca_certs'] = _certPath
23+
_http_init(self, *kList, **kw)
24+
httplib2.Http.__init__ = _new_http_init

0 commit comments

Comments
 (0)