summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrtobar <rtobarc@gmail.com>2021-10-06 17:49:44 (GMT)
committerGitHub <noreply@github.com>2021-10-06 17:49:44 (GMT)
commit0571b934f5f9198c3461a7b631d7073ac0a5676f (patch)
tree3dd970bd4e78e4331be6f8fa7fa82c40fa34cfbc
parent470145f572b53fe73518cda1eeacc56fec78c1b2 (diff)
downloadcpython-0571b934f5f9198c3461a7b631d7073ac0a5676f.zip
cpython-0571b934f5f9198c3461a7b631d7073ac0a5676f.tar.gz
cpython-0571b934f5f9198c3461a7b631d7073ac0a5676f.tar.bz2
bpo-45328: Avoid failure in OSs without TCP_NODELAY support (GH-28646)
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.
-rw-r--r--Lib/http/client.py8
-rw-r--r--Misc/NEWS.d/next/Library/2021-09-30-08-22-44.bpo-45328.8Z-Q0B.rst1
2 files changed, 8 insertions, 1 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 08cf2ed..a6ab135 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -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
@@ -939,7 +940,12 @@ class HTTPConnection:
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()
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 0000000..eeb4931
--- /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.