|
12 | 12 | Stream, STATE_HALF_CLOSED_LOCAL, STATE_OPEN, MAX_CHUNK, STATE_CLOSED
|
13 | 13 | )
|
14 | 14 | 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 | +) |
16 | 18 | from hyper.http20.window import FlowControlManager
|
17 | 19 | from hyper.http20.util import combine_repeated_headers, split_repeated_headers
|
18 | 20 | from hyper.compat import zlib_compressobj
|
@@ -1773,6 +1775,32 @@ def test_can_receive_trailers(self):
|
1773 | 1775 | # Confirm we closed the stream.
|
1774 | 1776 | assert s.state == STATE_CLOSED
|
1775 | 1777 |
|
| 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 | + |
1776 | 1804 | def test_reading_trailers_early_reads_all_data(self):
|
1777 | 1805 | in_frames = []
|
1778 | 1806 | headers = [('a', 'b'), ('c', 'd'), (':status', '200')]
|
|
0 commit comments