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

Commit 2b7a4fb

Browse files
committed
Use Window Manager objects in streams.
1 parent 7e0ff55 commit 2b7a4fb

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

hyper/http20/connection.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,11 @@ def _new_stream(self):
348348
"""
349349
Returns a new stream object for this connection.
350350
"""
351+
window_size = self._settings[SettingsFrame.INITIAL_WINDOW_SIZE]
351352
s = Stream(
352353
self.next_stream_id, self._send_cb, self._recv_cb,
353-
self._close_stream, self.encoder, self.decoder
354-
)
355-
s._out_flow_control_window = (
356-
self._settings[SettingsFrame.INITIAL_WINDOW_SIZE]
354+
self._close_stream, self.encoder, self.decoder,
355+
self.__wm_class(window_size)
357356
)
358357
self.next_stream_id += 2
359358

hyper/http20/stream.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,17 @@ def __init__(self,
5050
recv_cb,
5151
close_cb,
5252
header_encoder,
53-
header_decoder):
53+
header_decoder,
54+
window_manager):
5455
self.stream_id = stream_id
5556
self.state = STATE_IDLE
5657
self.headers = []
5758
self._queued_frames = collections.deque()
5859

5960
# There are two flow control windows: one for data we're sending,
6061
# one for data being sent to us.
62+
self._in_window_manager = window_manager
6163
self._out_flow_control_window = 65535
62-
self._in_flow_control_window = 65535
6364

6465
# This is the callback handed to the stream by its parent connection.
6566
# It is called when the stream wants to send data. It expects to
@@ -148,9 +149,10 @@ def listlen(list):
148149

149150
# Increase the window size. Only do this if the data frame contains
150151
# actual data.
151-
if len(frame.data):
152+
increment = self._in_window_manager._handle_frame(len(frame.data))
153+
if increment:
152154
w = WindowUpdateFrame(self.stream_id)
153-
w.window_increment = len(frame.data)
155+
w.window_increment = increment
154156
self._data_cb(w)
155157

156158
return b''.join(data)

test/test_hyper.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from hyper.http20.response import HTTP20Response
1515
from hyper.http20.exceptions import HPACKDecodingError
16+
from hyper.http20.window import FlowControlManager
1617
from hyper.contrib import HTTP20Adapter
1718
import pytest
1819
import zlib
@@ -973,15 +974,15 @@ def test_connections_handle_resizing_header_tables_properly(self):
973974

974975
class TestHyperStream(object):
975976
def test_streams_have_ids(self):
976-
s = Stream(1, None, None, None, None, None)
977+
s = Stream(1, None, None, None, None, None, None)
977978
assert s.stream_id == 1
978979

979980
def test_streams_initially_have_no_headers(self):
980-
s = Stream(1, None, None, None, None, None)
981+
s = Stream(1, None, None, None, None, None, None)
981982
assert s.headers == []
982983

983984
def test_streams_can_have_headers(self):
984-
s = Stream(1, None, None, None, None, None)
985+
s = Stream(1, None, None, None, None, None, None)
985986
s.add_header("name", "value")
986987
assert s.headers == [("name", "value")]
987988

@@ -991,14 +992,14 @@ def data_callback(frame):
991992
assert frame.data == 'testkeyTestVal'
992993
assert frame.flags == set(['END_STREAM', 'END_HEADERS'])
993994

994-
s = Stream(1, data_callback, None, None, NullEncoder, None)
995+
s = Stream(1, data_callback, None, None, NullEncoder, None, None)
995996
s.add_header("TestKey", "TestVal")
996997
s.open(True)
997998

998999
assert s.state == STATE_HALF_CLOSED_LOCAL
9991000

10001001
def test_receiving_a_frame_queues_it(self):
1001-
s = Stream(1, None, None, None, None, None)
1002+
s = Stream(1, None, None, None, None, None, None)
10021003
s.receive_frame(Frame(0))
10031004
assert len(s._queued_frames) == 1
10041005

@@ -1008,7 +1009,7 @@ def data_callback(frame):
10081009
assert frame.data == b'Hi there!'
10091010
assert frame.flags == set(['END_STREAM'])
10101011

1011-
s = Stream(1, data_callback, None, None, NullEncoder, None)
1012+
s = Stream(1, data_callback, None, None, NullEncoder, None, None)
10121013
s.state = STATE_OPEN
10131014
s.send_data(BytesIO(b'Hi there!'), True)
10141015

@@ -1027,7 +1028,7 @@ def data_callback(frame):
10271028

10281029
data = b'test' * (MAX_CHUNK + 1)
10291030

1030-
s = Stream(1, data_callback, None, None, NullEncoder, None)
1031+
s = Stream(1, data_callback, None, None, NullEncoder, None, None)
10311032
s.state = STATE_OPEN
10321033
s.send_data(BytesIO(data), True)
10331034

@@ -1042,7 +1043,7 @@ def data_callback(frame):
10421043
assert frame.data == b'Hi there!'
10431044
assert frame.flags == set(['END_STREAM'])
10441045

1045-
s = Stream(1, data_callback, None, None, NullEncoder, None)
1046+
s = Stream(1, data_callback, None, None, NullEncoder, None, None)
10461047
s.state = STATE_OPEN
10471048
s.send_data(b'Hi there!', True)
10481049

@@ -1061,7 +1062,7 @@ def data_callback(frame):
10611062

10621063
data = b'test' * (MAX_CHUNK + 1)
10631064

1064-
s = Stream(1, data_callback, None, None, NullEncoder, None)
1065+
s = Stream(1, data_callback, None, None, NullEncoder, None, None)
10651066
s.state = STATE_OPEN
10661067
s.send_data(data, True)
10671068

@@ -1071,7 +1072,7 @@ def data_callback(frame):
10711072
assert s._out_flow_control_window == 65535 - len(data)
10721073

10731074
def test_windowupdate_frames_update_windows(self):
1074-
s = Stream(1, None, None, None, None, None)
1075+
s = Stream(1, None, None, None, None, None, None)
10751076
f = WindowUpdateFrame(1)
10761077
f.window_increment = 1000
10771078
s.receive_frame(f)
@@ -1090,7 +1091,7 @@ def inner():
10901091
s.receive_frame(in_frames.pop(0))
10911092
return inner
10921093

1093-
s = Stream(1, send_cb, None, None, None, None)
1094+
s = Stream(1, send_cb, None, None, None, None, None)
10941095
s._recv_cb = recv_cb(s)
10951096
s.state = STATE_HALF_CLOSED_LOCAL
10961097

@@ -1116,7 +1117,7 @@ def inner():
11161117
s.receive_frame(in_frames.pop(0))
11171118
return inner
11181119

1119-
s = Stream(1, send_cb, None, None, None, None)
1120+
s = Stream(1, send_cb, None, None, None, None, FlowControlManager(65535))
11201121
s._recv_cb = recv_cb(s)
11211122
s.state = STATE_HALF_CLOSED_LOCAL
11221123

@@ -1148,7 +1149,7 @@ def inner():
11481149
s.receive_frame(in_frames.pop(0))
11491150
return inner
11501151

1151-
s = Stream(1, send_cb, None, None, None, None)
1152+
s = Stream(1, send_cb, None, None, None, None, FlowControlManager(65535))
11521153
s._recv_cb = recv_cb(s)
11531154
s.state = STATE_HALF_CLOSED_LOCAL
11541155

0 commit comments

Comments
 (0)