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

Commit 06b5d10

Browse files
committed
Add a Stream.gettrailers() method.
This is needed so that we can lazily load trailers into the HTTP20Response object. We don't want to force ourselves to download every stream completely just in case it has trailers, but if we're asked for them we need to be able to get them.
1 parent 1da6520 commit 06b5d10

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

hyper/http20/stream.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ def receive_frame(self, frame):
243243
# We've handled the headers, zero them out.
244244
self.header_data = None
245245

246-
247246
def open(self, end):
248247
"""
249248
Open the stream. Does this by encoding and sending the headers: no more
@@ -300,6 +299,28 @@ def getheaders(self):
300299

301300
return self.response_headers
302301

302+
def gettrailers(self):
303+
"""
304+
Once all data has been sent on this connection, returns a key-value set
305+
of the trailers of the response to the original request.
306+
307+
.. warning:: Note that this method requires that the stream is
308+
totally exhausted. This means that, if you have not
309+
completely read from the stream, all stream data will be
310+
read into memory.
311+
312+
:returns: The key-value set of the trailers, or ``None`` if no trailers
313+
were sent.
314+
"""
315+
# Keep reading until the stream is done.
316+
# TODO: Right now this doesn't handle CONTINUATION blocks in trailers.
317+
# The idea of receiving such a thing is mind-boggling it's so unlikely,
318+
# but we should fix this up at some stage.
319+
while not self._remote_closed:
320+
self._recv_cb()
321+
322+
return self.response_trailers
323+
303324
def getpushes(self, capture_all=False):
304325
"""
305326
Returns a generator that yields push promises from the server. Note that

0 commit comments

Comments
 (0)