Skip to content

Commit

Permalink
bpo-45328: Avoid failure in OSs without TCP_NODELAY support (GH-28646) (
Browse files Browse the repository at this point in the history
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 <rtobarc@gmail.com>
  • Loading branch information
miss-islington and rtobar committed Oct 6, 2021
1 parent dcdeb96 commit 4c35a2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Lib/http/client.py
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
@@ -0,0 +1 @@
Fixed :class:`http.client.HTTPConnection` to work properly in OSs that don't support the ``TCP_NODELAY`` socket option.

0 comments on commit 4c35a2a

Please sign in to comment.