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

Commit 7543d22

Browse files
committed
Spot trailers.
1 parent 4f247e5 commit 7543d22

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

hyper/http20/stream.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
Each stream is identified by a monotonically increasing integer, assigned to
1414
the stream by the endpoint that initiated the stream.
1515
"""
16+
from .exceptions import ProtocolError
1617
from .frame import (
1718
FRAME_MAX_LEN, FRAMES, HeadersFrame, DataFrame, PushPromiseFrame,
1819
WindowUpdateFrame, ContinuationFrame, BlockedFrame
@@ -65,6 +66,10 @@ def __init__(self,
6566
# HEADERS..CONTINUATION frame sequence finishes.
6667
self.response_headers = None
6768

69+
# Set to a key-value set of the response trailers once their
70+
# HEADERS..CONTINUATION frame sequence finishes.
71+
self.response_trailers = None
72+
6873
# A dict mapping the promised stream ID of a pushed resource to a
6974
# key-value set of its request headers. Entries are added once their
7075
# PUSH_PROMISE..CONTINUATION frame sequence finishes.
@@ -224,8 +229,17 @@ def receive_frame(self, frame):
224229

225230
if 'END_HEADERS' in frame.flags:
226231
headers = self._decoder.decode(b''.join(self.header_data))
227-
if self.promised_stream_id is None:
228-
self.response_headers = headers
232+
233+
# The header block may be for trailers or headers. If we've already
234+
# received headers these _must_ be for trailers.
235+
if (self.promised_stream_id is None):
236+
if self.response_headers is None:
237+
self.response_headers = headers
238+
elif self.response_trailers is None:
239+
self.response_trailers = headers
240+
else:
241+
# Received too many headers blocks.
242+
raise ProtocolError("Too many header blocks.")
229243
else:
230244
self.promised_headers[self.promised_stream_id] = headers
231245

0 commit comments

Comments
 (0)