Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
bpo-45328: Avoid failure in OSs without TCP_NODELAY support
OSs without support for TCP_NODELAY will raise an OSError when trying to
set the socket option, but the show can still go on.
  • Loading branch information
rtobar committed Sep 30, 2021
commit 59a10e106a1258aabcad9d7cd69c15d261301fe9
8 changes: 7 additions & 1 deletion Lib/http/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

import email.parser
import email.message
import errno
import http
import io
import re
Expand Down Expand Up @@ -939,7 +940,12 @@ def connect(self):
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()
Expand Down