Skip to content

Commit

Permalink
Python 3: http.client.HTTPResponse reads too much
Browse files Browse the repository at this point in the history
The Python 3.6 documentation for HTTPConnection.get_response() has this
note:

    Note that you must have read the whole response before you can send
    a new request to the server.

As far as I understand, the problem is that HTTPResponse() wraps the raw
socket object in a buffered reader that reads ahead, so the first
response object gets all of the pipelined responses into the buffer of
the socket wrapper that is discarded and not passed over to subsequent
responses.
  • Loading branch information
mgedmin committed Oct 21, 2017
1 parent c6a7ab5 commit 1467426
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/zope/server/http/tests/test_httpserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,20 @@ def testPipelining(self):
b"Content-Length: %d\r\n"
b"\r\n"
b"%s")
to_send = b''
to_send = []
count = 25
for n in range(count):
body = b"Response #%d\r\n" % (n + 1)
if n + 1 < count:
conn = b'keep-alive'
else:
conn = b'close'
to_send += s % (conn, len(body), body)
to_send.append(s % (conn, len(body), body))

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((LOCALHOST, self.port))
sock.send(to_send)
for n in range(count):
for n, req in enumerate(to_send):
sock.send(req)
expect_body = b"Response #%d\r\n" % (n + 1)
response = ClientHTTPResponse(sock)
response.begin()
Expand Down

0 comments on commit 1467426

Please sign in to comment.