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

Commit 5c87a88

Browse files
committed
Test responses without bodies.
1 parent 8a69998 commit 5c87a88

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/test_integration.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,48 @@ def socket_handler(listener):
254254

255255
self.tear_down()
256256

257+
def test_receiving_responses_with_no_body(self):
258+
self.set_up()
259+
260+
recv_event = threading.Event()
261+
262+
def socket_handler(listener):
263+
sock = listener.accept()[0]
264+
265+
# We get two messages for the connection open and then a HEADERS
266+
# frame.
267+
sock.recv(65535)
268+
sock.recv(65535)
269+
sock.send(SettingsFrame(0).serialize())
270+
sock.recv(65535)
271+
272+
# Now, send the headers for the response. This response has no body.
273+
f = build_headers_frame([(':status', '204'), ('Content-Length', '0')])
274+
f.flags.add('END_STREAM')
275+
f.stream_id = 1
276+
sock.send(f.serialize())
277+
278+
# Wait for the message from the main thread.
279+
recv_event.wait()
280+
sock.close()
281+
282+
self._start_server(socket_handler)
283+
conn = HTTP20Connection(self.host, self.port)
284+
conn.request('GET', '/')
285+
resp = conn.getresponse()
286+
287+
# Confirm the status code.
288+
assert resp.status == 204
289+
290+
# Confirm that we can read this, but it has no body.
291+
assert resp.read() == b''
292+
293+
# Awesome, we're done now.
294+
recv_event.set()
295+
296+
self.tear_down()
297+
298+
257299
class TestRequestsAdapter(SocketLevelTest):
258300
def test_adapter_received_values(self):
259301
self.set_up()

0 commit comments

Comments
 (0)