@@ -1773,6 +1773,48 @@ def test_can_receive_trailers(self):
17731773 # Confirm we closed the stream.
17741774 assert s .state == STATE_CLOSED
17751775
1776+ def test_reading_trailers_early_reads_all_data (self ):
1777+ in_frames = []
1778+ headers = [('a' , 'b' ), ('c' , 'd' ), (':status' , '200' )]
1779+ trailers = [('e' , 'f' ), ('g' , 'h' )]
1780+
1781+ def recv_cb (s ):
1782+ def inner ():
1783+ s .receive_frame (in_frames .pop (0 ))
1784+ return inner
1785+
1786+ s = Stream (1 , None , None , None , None , FixedDecoder (headers ), FlowControlManager (65535 ))
1787+ s ._recv_cb = recv_cb (s )
1788+ s .state = STATE_HALF_CLOSED_LOCAL
1789+
1790+ # Provide the first HEADERS frame.
1791+ f = HeadersFrame (1 )
1792+ f .data = b'hi there!'
1793+ f .flags .add ('END_HEADERS' )
1794+ in_frames .append (f )
1795+
1796+ # Provide some data.
1797+ f = DataFrame (1 )
1798+ f .data = b'testdata'
1799+ in_frames .append (f )
1800+
1801+ # Provide the trailers.
1802+ f = HeadersFrame (1 )
1803+ f .data = b'hi there again!'
1804+ f .flags .add ('END_STREAM' )
1805+ f .flags .add ('END_HEADERS' )
1806+ in_frames .append (f )
1807+
1808+ # Begin by reading the first headers.
1809+ assert s .getheaders () == headers
1810+
1811+ # Now, replace the dummy decoder to ensure we get a new header block.
1812+ s ._decoder = FixedDecoder (trailers )
1813+
1814+ # Ask for the trailers. This should also read the data frames.
1815+ assert s .gettrailers () == trailers
1816+ assert s .data == [b'testdata' ]
1817+
17761818
17771819class TestResponse (object ):
17781820 def test_status_is_stripped_from_headers (self ):
0 commit comments