summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_httplib.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-03-08 07:59:37 (GMT)
committerGitHub <noreply@github.com>2021-03-08 07:59:37 (GMT)
commitc6e7cf1ee09c88d35e6703c33a61eca7b9db54f3 (patch)
tree941937755bf1c1eba5c3c80d894ffb81b678d76f /Lib/test/test_httplib.py
parent2c0a0b04a42dc4965fcfaef936f497e44f06dea5 (diff)
downloadcpython-c6e7cf1ee09c88d35e6703c33a61eca7b9db54f3.zip
cpython-c6e7cf1ee09c88d35e6703c33a61eca7b9db54f3.tar.gz
cpython-c6e7cf1ee09c88d35e6703c33a61eca7b9db54f3.tar.bz2
bpo-43332: Buffer proxy connection setup packets before sending. (GH-24780)
We now buffer the CONNECT request + tunnel HTTP headers into a single send call. This prevents the OS from generating multiple network packets for connection setup when not necessary, improving efficiency. (cherry picked from commit c25910a135c2245accadb324b40dd6453015e056) Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib/test/test_httplib.py')
-rw-r--r--Lib/test/test_httplib.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
index 28943f0..0fe8ead 100644
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -10,6 +10,7 @@ import threading
import warnings
import unittest
+from unittest import mock
TestCase = unittest.TestCase
from test import support
@@ -2021,6 +2022,23 @@ class TunnelTests(TestCase):
# This test should be removed when CONNECT gets the HTTP/1.1 blessing
self.assertNotIn(b'Host: proxy.com', self.conn.sock.data)
+ def test_tunnel_connect_single_send_connection_setup(self):
+ """Regresstion test for https://bugs.python.org/issue43332."""
+ with mock.patch.object(self.conn, 'send') as mock_send:
+ self.conn.set_tunnel('destination.com')
+ self.conn.connect()
+ self.conn.request('GET', '/')
+ mock_send.assert_called()
+ # Likely 2, but this test only cares about the first.
+ self.assertGreater(
+ len(mock_send.mock_calls), 1,
+ msg=f'unexpected number of send calls: {mock_send.mock_calls}')
+ proxy_setup_data_sent = mock_send.mock_calls[0][1][0]
+ self.assertIn(b'CONNECT destination.com', proxy_setup_data_sent)
+ self.assertTrue(
+ proxy_setup_data_sent.endswith(b'\r\n\r\n'),
+ msg=f'unexpected proxy data sent {proxy_setup_data_sent!r}')
+
def test_connect_put_request(self):
self.conn.set_tunnel('destination.com')
self.conn.request('PUT', '/', '')