Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions deproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __setitem__(self, key, value):
lower = key.lower()
for i, header in enumerate(self.headers):
if header[0].lower() == lower:
headers[i] = (header[0], value)
self.headers[i] = (header[0], value)
return
else:
self.add(key, value)
Expand Down Expand Up @@ -197,12 +197,7 @@ def __init__(self, code, message=None, headers=None, body=None):
"""

if message is None:
if code in message_by_response_code:
message = message_by_response_code[code]
elif int(code) in message_by_response_code:
message = message_by_response_code[int(code)]
else:
message = ''
message = ''

if headers is None:
headers = {}
Expand Down Expand Up @@ -429,7 +424,7 @@ def __init__(self, default_handler=None):

def make_request(self, url, method='GET', headers=None, request_body='',
default_handler=None, handlers=None,
add_default_headers=True):
add_default_headers=True, ssl_options={}):
"""
Make an HTTP request to the given url and return a MessageChain.

Expand Down Expand Up @@ -490,7 +485,7 @@ def make_request(self, url, method='GET', headers=None, request_body='',

request = Request(method, path, headers, request_body)

response = self.send_request(scheme, host, request)
response = self.send_request(scheme, host, request, ssl_options)

self.remove_message_chain(request_id)

Expand All @@ -501,7 +496,8 @@ def make_request(self, url, method='GET', headers=None, request_body='',

def create_ssl_connection(self, address,
timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
source_address=None,
ssl_options={}):
"""
Copied from the socket module and modified for ssl support.

Expand All @@ -525,7 +521,7 @@ def create_ssl_connection(self, address,
try:
sock = socket.socket(af, socktype, proto)

sock = ssl.wrap_socket(sock)
sock = ssl.wrap_socket(sock, **ssl_options)

if timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
sock.settimeout(timeout)
Expand All @@ -542,9 +538,9 @@ def create_ssl_connection(self, address,
if err is not None:
raise err
else:
raise error("getaddrinfo returns an empty list")
raise Exception("getaddrinfo returns an empty list")

def send_request(self, scheme, host, request):
def send_request(self, scheme, host, request, ssl_options={}):
"""Send the given request to the host and return the Response."""
logger.debug('sending request (scheme="%s", host="%s")' %
(scheme, host))
Expand Down Expand Up @@ -576,7 +572,7 @@ def send_request(self, scheme, host, request):

address = (hostname, port)
if scheme == 'https':
s = self.create_ssl_connection(address)
s = self.create_ssl_connection(address, ssl_options=ssl_options)
else:
s = socket.create_connection(address)

Expand Down