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

Commit 386f09e

Browse files
committed
Confirm three header blocks not allowed.
1 parent 6302d99 commit 386f09e

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

test/test_hyper.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
Stream, STATE_HALF_CLOSED_LOCAL, STATE_OPEN, MAX_CHUNK, STATE_CLOSED
1313
)
1414
from hyper.http20.response import HTTP20Response, HTTP20Push
15-
from hyper.http20.exceptions import HPACKDecodingError, HPACKEncodingError
15+
from hyper.http20.exceptions import (
16+
HPACKDecodingError, HPACKEncodingError, ProtocolError
17+
)
1618
from hyper.http20.window import FlowControlManager
1719
from hyper.http20.util import combine_repeated_headers, split_repeated_headers
1820
from hyper.compat import zlib_compressobj
@@ -1773,6 +1775,32 @@ def test_can_receive_trailers(self):
17731775
# Confirm we closed the stream.
17741776
assert s.state == STATE_CLOSED
17751777

1778+
def test_cannot_receive_three_header_blocks(self):
1779+
first = [('a', 'b'), ('c', 'd'), (':status', '200')]
1780+
1781+
s = Stream(1, None, None, None, None, FixedDecoder(first), None)
1782+
s.state = STATE_HALF_CLOSED_LOCAL
1783+
1784+
# Provide the first two header frames.
1785+
f = HeadersFrame(1)
1786+
f.data = b'hi there!'
1787+
f.flags.add('END_HEADERS')
1788+
s.receive_frame(f)
1789+
1790+
f = HeadersFrame(1)
1791+
f.data = b'hi there again!'
1792+
f.flags.add('END_HEADERS')
1793+
s.receive_frame(f)
1794+
1795+
# Provide the third. This one blows up.
1796+
f = HeadersFrame(1)
1797+
f.data = b'hi there again!'
1798+
f.flags.add('END_STREAM')
1799+
f.flags.add('END_HEADERS')
1800+
1801+
with pytest.raises(ProtocolError):
1802+
s.receive_frame(f)
1803+
17761804
def test_reading_trailers_early_reads_all_data(self):
17771805
in_frames = []
17781806
headers = [('a', 'b'), ('c', 'd'), (':status', '200')]

0 commit comments

Comments
 (0)