Skip to content

Commit 4c35a2a

Browse files
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 0571b93) Co-authored-by: rtobar <[email protected]>
1 parent dcdeb96 commit 4c35a2a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

Lib/http/client.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070

7171
import email.parser
7272
import email.message
73+
import errno
7374
import http
7475
import io
7576
import re
@@ -939,7 +940,12 @@ def connect(self):
939940
sys.audit("http.client.connect", self, self.host, self.port)
940941
self.sock = self._create_connection(
941942
(self.host,self.port), self.timeout, self.source_address)
942-
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
943+
# Might fail in OSs that don't implement TCP_NODELAY
944+
try:
945+
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
946+
except OSError as e:
947+
if e.errno != errno.ENOPROTOOPT:
948+
raise
943949

944950
if self._tunnel_host:
945951
self._tunnel()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed :class:`http.client.HTTPConnection` to work properly in OSs that don't support the ``TCP_NODELAY`` socket option.

0 commit comments

Comments
 (0)