summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-10-06 18:29:23 (GMT)
committerGitHub <noreply@github.com>2021-10-06 18:29:23 (GMT)
commit4c35a2aa80d7f55573d83651883d8733fac01e31 (patch)
treeec77fd1af76fa9d3ea74b342ce75d29974716397 /Lib
parentdcdeb96495fa105098544e2be7b74fa288589912 (diff)
downloadcpython-4c35a2aa80d7f55573d83651883d8733fac01e31.zip
cpython-4c35a2aa80d7f55573d83651883d8733fac01e31.tar.gz
cpython-4c35a2aa80d7f55573d83651883d8733fac01e31.tar.bz2
bpo-45328: Avoid failure in OSs without TCP_NODELAY support (GH-28646) (GH-28771)
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>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/http/client.py8
1 files changed, 7 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()