Skip to content

Commit 11effd3

Browse files
committed
Complete SSL support by using a HTTPSConnection when needed.
1 parent ecf2cc3 commit 11effd3

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pusher/__init__.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,20 @@
1919
app_id_re = re.compile('^[0-9]+$')
2020

2121
def url2options(url):
22+
port = None
2223
if url.startswith('http://'):
2324
url = url[7:]
25+
port = 80
2426
elif url.startswith('https://'):
2527
url = url[8:]
28+
port = 443
2629
else:
2730
assert False, "invalid URL"
2831
key, url = url.split(':', 1)
2932
secret, url = url.split('@', 1)
3033
host, url = url.split('/', 1)
3134
url, app_id = url.split('/', 1)
32-
return {'key': key, 'secret': secret, 'host': host, 'app_id': app_id}
35+
return {'key': key, 'secret': secret, 'host': host, 'app_id': app_id, 'port': port }
3336

3437
def pusher_from_url(url=None):
3538
url = url or os.environ['PUSHER_URL']
@@ -97,7 +100,10 @@ def compose_querystring(self, event, json_data, socket_id):
97100
return ret
98101

99102
def send_request(self, signed_path, data_string, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
100-
http = httplib.HTTPConnection(self.pusher.host, self.pusher.port, timeout=timeout)
103+
if self.pusher.port == 443:
104+
http = httplib.HTTPSConnection(self.pusher.host, self.pusher.port, timeout=timeout)
105+
else:
106+
http = httplib.HTTPConnection(self.pusher.host, self.pusher.port, timeout=timeout)
101107
http.request('POST', signed_path, data_string, {'Content-Type': 'application/json'})
102108
resp = http.getresponse()
103109
return resp.status, resp.read()

0 commit comments

Comments
 (0)