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

Commit d09c017

Browse files
committed
Throw upgrade exceptions from HTTP/1.1.
1 parent b5e70fe commit d09c017

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

hyper/http11/connection.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from .response import HTTP11Response
1313
from ..tls import wrap_socket
1414
from ..common.bufsocket import BufferedSocket
15+
from ..common.exceptions import TLSUpgrade
1516
from ..common.headers import HTTPHeaderMap
1617
from ..common.util import to_bytestring
1718
from ..compat import bytes
@@ -84,12 +85,17 @@ def connect(self):
8485
"""
8586
if self._sock is None:
8687
sock = socket.create_connection((self.host, self.port), 5)
88+
proto = None
8789

8890
if self.secure:
8991
sock, proto = wrap_socket(sock, self.host)
90-
assert proto in ('http/1.1', None)
9192

92-
self._sock = BufferedSocket(sock, self.network_buffer_size)
93+
sock = BufferedSocket(sock, self.network_buffer_size)
94+
95+
if proto not in ('http/1.1', None):
96+
raise TLSUpgrade(proto, sock)
97+
98+
self._sock = sock
9399

94100
return
95101

0 commit comments

Comments
 (0)