Skip to content

Commit 92018a0

Browse files
bpo-45328: Avoid failure in OSs without TCP_NODELAY support (GH-28646) (GH-28770)
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 <rtobarc@gmail.com>
1 parent 496d1aa commit 92018a0

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

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
@@ -944,7 +945,12 @@ def connect(self):
944945
"""Connect to the host and port specified in __init__."""
945946
self.sock = self._create_connection(
946947
(self.host,self.port), self.timeout, self.source_address)
947-
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
948+
# Might fail in OSs that don't implement TCP_NODELAY
949+
try:
950+
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
951+
except OSError as e:
952+
if e.errno != errno.ENOPROTOOPT:
953+
raise
948954

949955
if self._tunnel_host:
950956
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)