]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45328: Avoid failure in OSs without TCP_NODELAY support (GH-28646) (GH-28770)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 6 Oct 2021 18:29:41 +0000 (11:29 -0700)
committerGitHub <noreply@github.com>
Wed, 6 Oct 2021 18:29:41 +0000 (20:29 +0200)
Operating systems without support for TCP_NODELAY will raise an OSError
when trying to set the socket option, but the show can still go on.
(cherry picked from commit 0571b934f5f9198c3461a7b631d7073ac0a5676f)

Co-authored-by: rtobar <rtobarc@gmail.com>
Lib/http/client.py
Misc/NEWS.d/next/Library/2021-09-30-08-22-44.bpo-45328.8Z-Q0B.rst [new file with mode: 0644]

index 0fd9021b4a785d389da2ddfa3a77bec11a6aca31..a98432e56850635722efed917404a6f8532bfee7 100644 (file)
@@ -70,6 +70,7 @@ Req-sent-unread-response       _CS_REQ_SENT       <response_class>
 
 import email.parser
 import email.message
+import errno
 import http
 import io
 import re
@@ -944,7 +945,12 @@ class HTTPConnection:
         """Connect to the host and port specified in __init__."""
         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()
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 (file)
index 0000000..eeb4931
--- /dev/null
@@ -0,0 +1 @@
+Fixed :class:`http.client.HTTPConnection` to work properly in OSs that don't support the ``TCP_NODELAY`` socket option.