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

Commit 9829fb2

Browse files
committed
Add 'secure' property.
1 parent e176959 commit 9829fb2

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

hyper/http11/connection.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,31 @@ class HTTP11Connection(object):
2626
hostname, and optionally may include a port: for example,
2727
``'twitter.com'``, ``'twitter.com:443'`` or ``'127.0.0.1'``.
2828
:param port: (optional) The port to connect to. If not provided and one also
29-
isn't provided in the ``host`` parameter, defaults to 443.
29+
isn't provided in the ``host`` parameter, defaults to 80.
30+
:param secure: (optional) Whether the request should use TLS. Defaults to
31+
``False`` for most requests, but to ``True`` for any request issued to
32+
port 443.
3033
"""
31-
def __init__(self, host, port):
34+
def __init__(self, host, port=None, secure=None):
3235
if port is None:
3336
try:
3437
self.host, self.port = host.split(':')
3538
self.port = int(self.port)
3639
except ValueError:
37-
self.host, self.port = host, 443
40+
self.host, self.port = host, 80
3841
else:
3942
self.host, self.port = host, port
4043

44+
# Record whether we plan to secure the request. In future this should
45+
# be extended to a security profile, but a bool will do for now.
46+
# TODO: Actually do something with this!
47+
if secure is not None:
48+
self.secure = secure
49+
elif self.port == 443:
50+
self.secure = True
51+
else:
52+
self.secure = False
53+
4154
self._sock = None
4255

4356
#: The size of the in-memory buffer used to store data from the

0 commit comments

Comments
 (0)