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

Add force_proto kwarg on contrib HTTP20Adapter #214

Open
wants to merge 5 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hyper/common/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ def __init__(self,
window_manager=None,
enable_push=False,
ssl_context=None,
force_proto=None,
proxy_host=None,
proxy_port=None,
**kwargs):
Expand All @@ -64,7 +65,7 @@ def __init__(self,
}
self._h2_kwargs = {
'window_manager': window_manager, 'enable_push': enable_push,
'secure': secure, 'ssl_context': ssl_context,
'secure': secure, 'ssl_context': ssl_context, 'force_proto': force_proto,
'proxy_host': proxy_host, 'proxy_port': proxy_port
}

Expand Down
4 changes: 3 additions & 1 deletion hyper/contrib.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class HTTP20Adapter(HTTPAdapter):
def __init__(self, *args, **kwargs):
#: A mapping between HTTP netlocs and ``HTTP20Connection`` objects.
self.connections = {}
self.force_proto = kwargs.get('force_proto')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than grab this out of kwargs, let's make it an explicit keyword argument.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You got it. Would you rather I edit and squash the commit, or just add a new one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New commits are fine. =) I'm not that precious about history.


def get_connection(self, host, port, scheme):
"""
Expand All @@ -41,7 +42,8 @@ def get_connection(self, host, port, scheme):
try:
conn = self.connections[(host, port, scheme)]
except KeyError:
conn = HTTPConnection(host, port, secure=secure)
conn = HTTPConnection(host, port, secure=secure,
force_proto=self.force_proto)
self.connections[(host, port, scheme)] = conn

return conn
Expand Down
3 changes: 2 additions & 1 deletion test/test_abstraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,15 @@ def test_h1_kwargs(self):
def test_h2_kwargs(self):
c = HTTPConnection(
'test', 443, secure=False, window_manager=True, enable_push=True,
ssl_context=True, proxy_host=False, proxy_port=False, other_kwarg=True
ssl_context=True, force_proto=False, proxy_host=False, proxy_port=False, other_kwarg=True
)

assert c._h2_kwargs == {
'window_manager': True,
'enable_push': True,
'secure': False,
'ssl_context': True,
'force_proto': False,
'proxy_host': False,
'proxy_port': False,
'other_kwarg': True,
Expand Down