-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhttpshandler.py
41 lines (29 loc) · 1.39 KB
/
httpshandler.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from .sslsocket import SSLSocket
import socket
import errno
from http.client import HTTPConnection, HTTPSConnection
from urllib.request import HTTPSHandler as HTTPSHandlerBase
class SSLConnection(HTTPSConnection):
def __init__(self, host, port=None, context=None, client_certificate=None, strict=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT, **kwargs):
HTTPConnection.__init__(self, host, port, strict, timeout)
self._client_certificate = client_certificate
self._context = context
def connect(self):
s = socket.create_connection((self.host, self.port))
if self._tunnel_host:
self.sock = s
self._tunnel()
ssl_sock = SSLSocket(s,
server_hostname=self.host,
client_certificate=self._client_certificate,
context=self._context)
self.sock = ssl_sock
class HTTPSHandler(HTTPSHandlerBase):
def __init__(self, client_certificate=None, context=None, *args, **kwargs):
super().__init__(self, *args, **kwargs)
self._client_certificate = client_certificate
self._context = context
def https_open(self, req):
def _SSLConnection(host, **kwargs):
return SSLConnection(host, context=self._context, client_certificate=self._client_certificate, **kwargs)
return self.do_open(_SSLConnection, req)