Skip to content

Commit

Permalink
Merge pull request #80 from apolcyn/zero_padding_fix
Browse files Browse the repository at this point in the history
account for pad length field in flow control if zero valued
  • Loading branch information
Lukasa committed Feb 18, 2017
2 parents e1ebcd5 + 5e8547e commit 202cf09
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion hyperframe/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,11 @@ def flow_controlled_length(self):
The length of the frame that needs to be accounted for when considering
flow control.
"""
padding_len = self.total_padding + 1 if self.total_padding else 0
padding_len = 0
if 'PADDED' in self.flags:
# Account for extra 1-byte padding length field, which is still
# present if possibly zero-valued.
padding_len = self.total_padding + 1
return len(self.data) + padding_len


Expand Down
8 changes: 8 additions & 0 deletions test/test_frames.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ def test_data_frame_with_padding_calculates_flow_control_len(self):

assert f.flow_controlled_length == 19

def test_data_frame_zero_length_padding_calculates_flow_control_len(self):
f = DataFrame(1)
f.flags = set(['PADDED'])
f.data = b'testdata'
f.pad_length = 0

assert f.flow_controlled_length == len(b'testdata') + 1

def test_data_frame_without_padding_calculates_flow_control_len(self):
f = DataFrame(1)
f.data = b'testdata'
Expand Down

0 comments on commit 202cf09

Please sign in to comment.