diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2013-01-02 21:10:47 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2013-01-02 21:10:47 (GMT) |
commit | 90e477455873c2b701d5eb0bc751da7ac9510754 (patch) | |
tree | e616f7bea00a08d8bc58a0e623bfb038bdb3f597 /Lib/test/test_httplib.py | |
parent | f42267642398be24049c6a618997c2ef1fe51b8a (diff) | |
download | cpython-90e477455873c2b701d5eb0bc751da7ac9510754.zip cpython-90e477455873c2b701d5eb0bc751da7ac9510754.tar.gz cpython-90e477455873c2b701d5eb0bc751da7ac9510754.tar.bz2 |
Issue #16833: In http.client.HTTPConnection, do not concatenate the request headers and body when the payload exceeds 16 KB, since it can consume more memory for no benefit.
Patch by Benno Leslie.
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r-- | Lib/test/test_httplib.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index 9c53e9c..e2d644d 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -27,8 +27,10 @@ class FakeSocket: self.text = text self.fileclass = fileclass self.data = b'' + self.sendall_calls = 0 def sendall(self, data): + self.sendall_calls += 1 self.data += data def makefile(self, mode, bufsize=None): @@ -558,6 +560,28 @@ class BasicTest(TestCase): self.assertEqual(resp.read(), b'') self.assertTrue(resp.isclosed()) + def test_delayed_ack_opt(self): + # Test that Nagle/delayed_ack optimistaion works correctly. + + # For small payloads, it should coalesce the body with + # headers, resulting in a single sendall() call + conn = client.HTTPConnection('example.com') + sock = FakeSocket(None) + conn.sock = sock + body = b'x' * (conn.mss - 1) + conn.request('POST', '/', body) + self.assertEqual(sock.sendall_calls, 1) + + # For large payloads, it should send the headers and + # then the body, resulting in more than one sendall() + # call + conn = client.HTTPConnection('example.com') + sock = FakeSocket(None) + conn.sock = sock + body = b'x' * conn.mss + conn.request('POST', '/', body) + self.assertGreater(sock.sendall_calls, 1) + class OfflineTest(TestCase): def test_responses(self): self.assertEqual(client.responses[client.NOT_FOUND], "Not Found") |