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

Commit 3f84dce

Browse files
committed
Update connection constructors with proxies param
1 parent b05c817 commit 3f84dce

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

hyper/common/connection.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ class HTTPConnection(object):
4040
:meth:`get_pushes() <hyper.HTTP20Connection.get_pushes>`).
4141
:param ssl_context: (optional) A class with custom certificate settings.
4242
If not provided then hyper's default ``SSLContext`` is used instead.
43+
:param proxies: (optional) A dictionary whose keys are the scheme used
44+
(http or https) and the value being the url of the proxy).
4345
"""
4446
def __init__(self,
4547
host,
@@ -48,14 +50,15 @@ def __init__(self,
4850
window_manager=None,
4951
enable_push=False,
5052
ssl_context=None,
53+
proxies=None,
5154
**kwargs):
5255

5356
self._host = host
5457
self._port = port
55-
self._h1_kwargs = {'secure': secure, 'ssl_context': ssl_context}
58+
self._h1_kwargs = {'secure': secure, 'ssl_context': ssl_context, 'proxies': proxies }
5659
self._h2_kwargs = {
5760
'window_manager': window_manager, 'enable_push': enable_push,
58-
'secure': secure, 'ssl_context': ssl_context
61+
'secure': secure, 'ssl_context': ssl_context, 'proxies': proxies
5962
}
6063

6164
# Add any unexpected kwargs to both dictionaries.

hyper/http11/connection.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,11 @@ class HTTP11Connection(object):
4747
port 443.
4848
:param ssl_context: (optional) A class with custom certificate settings.
4949
If not provided then hyper's default ``SSLContext`` is used instead.
50+
:param proxies: (optional) A dictionary whose keys are the scheme used
51+
(http or https) and the value being the url of the proxy).
5052
"""
51-
def __init__(self, host, port=None, secure=None, ssl_context=None,
52-
**kwargs):
53+
def __init__(self, host, port=None, secure=None, ssl_context=None,
54+
proxies=None, **kwargs):
5355
if port is None:
5456
try:
5557
self.host, self.port = host.split(':')
@@ -73,6 +75,7 @@ def __init__(self, host, port=None, secure=None, ssl_context=None,
7375
self._send_http_upgrade = not self.secure
7476

7577
self.ssl_context = ssl_context
78+
self.proxies = proxies
7679
self._sock = None
7780

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

hyper/http20/connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ class HTTP20Connection(object):
5656
:meth:`get_pushes() <hyper.HTTP20Connection.get_pushes>`).
5757
:param ssl_context: (optional) A class with custom certificate settings.
5858
If not provided then hyper's default ``SSLContext`` is used instead.
59+
:param proxies: (optional) A dictionary whose keys are the scheme used
60+
(http or https) and the value being the url of the proxy).
5961
"""
6062
def __init__(self, host, port=None, secure=None, window_manager=None, enable_push=False,
61-
ssl_context=None, **kwargs):
63+
ssl_context=None, proxies=None, **kwargs):
6264
"""
6365
Creates an HTTP/2 connection to a specific server.
6466
"""
@@ -80,6 +82,7 @@ def __init__(self, host, port=None, secure=None, window_manager=None, enable_pus
8082

8183
self._enable_push = enable_push
8284
self.ssl_context = ssl_context
85+
self.proxies = proxies
8386

8487
#: The size of the in-memory buffer used to store data from the
8588
#: network. This is used as a performance optimisation. Increase buffer

test/test_abstraction.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,28 @@ class TestHTTPConnection(object):
88
def test_h1_kwargs(self):
99
c = HTTPConnection(
1010
'test', 443, secure=False, window_manager=True, enable_push=True,
11-
ssl_context=False, other_kwarg=True
11+
ssl_context=False, proxies=False, other_kwarg=True
1212
)
1313

1414
assert c._h1_kwargs == {
1515
'secure': False,
1616
'ssl_context': False,
17+
'proxies': False,
1718
'other_kwarg': True,
1819
}
1920

2021
def test_h2_kwargs(self):
2122
c = HTTPConnection(
2223
'test', 443, secure=False, window_manager=True, enable_push=True,
23-
ssl_context=True, other_kwarg=True
24+
ssl_context=True, proxies=False, other_kwarg=True
2425
)
2526

2627
assert c._h2_kwargs == {
2728
'window_manager': True,
2829
'enable_push': True,
2930
'secure': False,
3031
'ssl_context': True,
32+
'proxies': False,
3133
'other_kwarg': True,
3234
}
3335

0 commit comments

Comments
 (0)