From 59a10e106a1258aabcad9d7cd69c15d261301fe9 Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Thu, 30 Sep 2021 16:16:26 +0800 Subject: [PATCH 1/2] bpo-45328: Avoid failure in OSs without TCP_NODELAY support OSs without support for TCP_NODELAY will raise an OSError when trying to set the socket option, but the show can still go on. --- Lib/http/client.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/http/client.py b/Lib/http/client.py index 08cf2ed9b3716b..a6ab135b2c3879 100644 --- a/Lib/http/client.py +++ b/Lib/http/client.py @@ -70,6 +70,7 @@ import email.parser import email.message +import errno import http import io import re @@ -939,7 +940,12 @@ def connect(self): sys.audit("http.client.connect", self, self.host, self.port) self.sock = self._create_connection( (self.host,self.port), self.timeout, self.source_address) - self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) + # Might fail in OSs that don't implement TCP_NODELAY + try: + self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1) + except OSError as e: + if e.errno != errno.ENOPROTOOPT: + raise if self._tunnel_host: self._tunnel() From dd8c2004062d6b644785e982be819f36acdab3ff Mon Sep 17 00:00:00 2001 From: Rodrigo Tobar Date: Tue, 5 Oct 2021 10:32:00 +0800 Subject: [PATCH 2/2] bpo-45328: Document fix in http.client.HTTPConnection --- .../NEWS.d/next/Library/2021-09-30-08-22-44.bpo-45328.8Z-Q0B.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2021-09-30-08-22-44.bpo-45328.8Z-Q0B.rst diff --git a/Misc/NEWS.d/next/Library/2021-09-30-08-22-44.bpo-45328.8Z-Q0B.rst b/Misc/NEWS.d/next/Library/2021-09-30-08-22-44.bpo-45328.8Z-Q0B.rst new file mode 100644 index 00000000000000..eeb49310e8f66a --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-09-30-08-22-44.bpo-45328.8Z-Q0B.rst @@ -0,0 +1 @@ +Fixed :class:`http.client.HTTPConnection` to work properly in OSs that don't support the ``TCP_NODELAY`` socket option.