Skip to content
This repository was archived by the owner on Jan 13, 2021. It is now read-only.

Commit b093cc7

Browse files
committed
Merge branch 'proto_override' of https://github.com/markjenkins/hyper into markjenkins-proto_override
2 parents dc20403 + 147142f commit b093cc7

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

hyper/http20/connection.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ class HTTP20Connection(object):
6565
and one also isn't provided in the ``proxy`` parameter, defaults to 8080.
6666
"""
6767
def __init__(self, host, port=None, secure=None, window_manager=None, enable_push=False,
68-
ssl_context=None, proxy_host=None, proxy_port=None, **kwargs):
68+
ssl_context=None, proxy_host=None, proxy_port=None,
69+
force_proto=None, **kwargs):
6970
"""
7071
Creates an HTTP/2 connection to a specific server.
7172
"""
@@ -100,6 +101,8 @@ def __init__(self, host, port=None, secure=None, window_manager=None, enable_pus
100101
#: Defaults to 64kB.
101102
self.network_buffer_size = 65536
102103

104+
self.force_proto = force_proto
105+
103106
# Create the mutable state.
104107
self.__wm_class = window_manager or FlowControlManager
105108
self.__init_state()
@@ -235,7 +238,8 @@ def connect(self):
235238

236239
if self.secure:
237240
assert not self.proxy_host, "Using a proxy with HTTPS not yet supported."
238-
sock, proto = wrap_socket(sock, host, self.ssl_context)
241+
sock, proto = wrap_socket(sock, host, self.ssl_context,
242+
force_proto=self.force_proto)
239243
else:
240244
proto = H2C_PROTOCOL
241245

hyper/tls.py

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
cert_loc = path.join(path.dirname(__file__), 'certs.pem')
2525

2626

27-
def wrap_socket(sock, server_hostname, ssl_context=None):
27+
def wrap_socket(sock, server_hostname, ssl_context=None, force_proto=None):
2828
"""
2929
A vastly simplified SSL wrapping function. We'll probably extend this to
3030
do more things later.
@@ -49,16 +49,19 @@ def wrap_socket(sock, server_hostname, ssl_context=None):
4949
except AttributeError:
5050
ssl.verify_hostname(ssl_sock, server_hostname) # pyopenssl
5151

52-
proto = None
52+
if force_proto != None:
53+
proto = force_proto
54+
else:
55+
proto = None
5356

54-
# ALPN is newer, so we prefer it over NPN. The odds of us getting different
55-
# answers is pretty low, but let's be sure.
56-
with ignore_missing():
57-
proto = ssl_sock.selected_alpn_protocol()
57+
# ALPN is newer, so we prefer it over NPN. The odds of us getting
58+
# different answers is pretty low, but let's be sure.
59+
with ignore_missing():
60+
proto = ssl_sock.selected_alpn_protocol()
5861

59-
with ignore_missing():
60-
if proto is None:
61-
proto = ssl_sock.selected_npn_protocol()
62+
with ignore_missing():
63+
if proto is None:
64+
proto = ssl_sock.selected_npn_protocol()
6265

6366
return (ssl_sock, proto)
6467

0 commit comments

Comments
 (0)