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

Commit

Permalink
Merge pull request #191 from Lukasa/issue/190
Browse files Browse the repository at this point in the history
Correctly initialize stream flow control windows.
  • Loading branch information
Lukasa committed Jan 19, 2016
2 parents 3951307 + c94507b commit e1fd136
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
11 changes: 7 additions & 4 deletions hyper/http20/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@

log = logging.getLogger(__name__)

DEFAULT_WINDOW_SIZE = 65535


class HTTP20Connection(object):
"""
An object representing a single HTTP/2 connection to a server.
Expand Down Expand Up @@ -59,7 +62,7 @@ class HTTP20Connection(object):
If not provided then hyper's default ``SSLContext`` is used instead.
:param proxy_host: (optional) The proxy to connect to. This can be an IP address
or a host name and may include a port.
:param proxy_port: (optional) The proxy port to connect to. If not provided
:param proxy_port: (optional) The proxy port to connect to. If not provided
and one also isn't provided in the ``proxy`` parameter, defaults to 8080.
"""
def __init__(self, host, port=None, secure=None, window_manager=None, enable_push=False,
Expand Down Expand Up @@ -137,7 +140,7 @@ def __init_state(self):

# Values for the settings used on an HTTP/2 connection.
self._settings = {
SettingsFrame.INITIAL_WINDOW_SIZE: 65535,
SettingsFrame.INITIAL_WINDOW_SIZE: DEFAULT_WINDOW_SIZE,
SettingsFrame.SETTINGS_MAX_FRAME_SIZE: FRAME_MAX_LEN,
}

Expand Down Expand Up @@ -513,9 +516,9 @@ def _new_stream(self, stream_id=None, local_closed=False):
s = Stream(
stream_id or self.next_stream_id, self._send_cb, self._recv_cb,
self._close_stream, self.encoder, self.decoder,
self.__wm_class(window_size), local_closed
self.__wm_class(DEFAULT_WINDOW_SIZE), local_closed
)
s._out_flow_control_window = self._out_flow_control_window
s._out_flow_control_window = window_size
self.streams[s.stream_id] = s
self.next_stream_id += 2

Expand Down
16 changes: 16 additions & 0 deletions test/test_hyper.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,22 @@ def test_connections_handle_resizing_max_frame_size_properly(self):
assert f2.stream_id == 0
assert f2.flags == set(['ACK'])

def test_connections_handle_resizing_initial_window_size(self):
sock = DummySocket()
f = SettingsFrame(0)
f.settings[SettingsFrame.INITIAL_WINDOW_SIZE] = 256
c = HTTP20Connection('www.google.com')
c._sock = sock

# 'Receive' the SETTINGS frame.
c.receive_frame(f)

# Open a new stream.
c.request('GET', '/')

# Confirm that the stream has the correct window size.
assert c.streams[1]._out_flow_control_window == 256

def test_connections_handle_too_small_max_frame_size_properly(self):
sock = DummySocket()
f = SettingsFrame(0)
Expand Down

0 comments on commit e1fd136

Please sign in to comment.