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

Commit ceeb27f

Browse files
committed
Prove chunked logic works.
1 parent 3172111 commit ceeb27f

File tree

2 files changed

+69
-3
lines changed

2 files changed

+69
-3
lines changed

hyper/http20/response.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,6 @@ def read_chunked(self, decode_content=True):
155155
if decode_content and self._decompressobj:
156156
yield self._decompressobj.flush()
157157

158-
self.close()
159-
160158
return
161159

162160
def fileno(self):

test/test_integration.py

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
import requests
1010
import threading
11+
import time
1112
import hyper
1213
import hyper.http11.connection
1314
import pytest
@@ -555,7 +556,6 @@ def socket_handler(listener):
555556

556557
self.tear_down()
557558

558-
559559
def test_resetting_stream_with_frames_in_flight(self):
560560
"""
561561
Hyper emits only one RST_STREAM frame, despite the other frames in
@@ -650,6 +650,74 @@ def socket_handler(listener):
650650

651651
self.tear_down()
652652

653+
def test_read_chunked_http2(self):
654+
self.set_up()
655+
656+
recv_event = threading.Event()
657+
wait_event = threading.Event()
658+
659+
def socket_handler(listener):
660+
sock = listener.accept()[0]
661+
662+
# We get two messages for the connection open and then a HEADERS
663+
# frame.
664+
receive_preamble(sock)
665+
sock.recv(65535)
666+
667+
# Now, send the headers for the response. This response has a body.
668+
f = build_headers_frame([(':status', '200')])
669+
f.stream_id = 1
670+
sock.send(f.serialize())
671+
672+
# Send the first two chunks.
673+
f = DataFrame(1)
674+
f.data = b'hello'
675+
sock.sendall(f.serialize())
676+
f = DataFrame(1)
677+
f.data = b'there'
678+
sock.sendall(f.serialize())
679+
680+
# Now, delay a bit. We want to wait a half a second before we send
681+
# the next frame.
682+
wait_event.wait(5)
683+
time.sleep(0.5)
684+
f = DataFrame(1)
685+
f.data = b'world'
686+
f.flags.add('END_STREAM')
687+
sock.sendall(f.serialize())
688+
689+
# Wait for the message from the main thread.
690+
recv_event.set()
691+
sock.close()
692+
693+
self._start_server(socket_handler)
694+
conn = self.get_connection()
695+
conn.request('GET', '/')
696+
resp = conn.get_response()
697+
698+
# Confirm the status code.
699+
assert resp.status == 200
700+
701+
# Confirm that we can read this, but it has no body. First two chunks
702+
# should be easy, then set the event and read the next one.
703+
chunks = resp.read_chunked()
704+
first_chunk = next(chunks)
705+
second_chunk = next(chunks)
706+
wait_event.set()
707+
third_chunk = next(chunks)
708+
709+
with pytest.raises(StopIteration):
710+
next(chunks)
711+
712+
assert first_chunk == b'hello'
713+
assert second_chunk == b'there'
714+
assert third_chunk == b'world'
715+
716+
# Awesome, we're done now.
717+
recv_event.wait(5)
718+
719+
self.tear_down()
720+
653721

654722
class TestRequestsAdapter(SocketLevelTest):
655723
# This uses HTTP/2.

0 commit comments

Comments
 (0)