mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
http.client: disable Nagle's algorithm (closes #23302)
Patch by Demian Brecht.
This commit is contained in:
parent
d775bcabe7
commit
9d8a3ad02a
3 changed files with 11 additions and 43 deletions
|
@ -681,14 +681,6 @@ class HTTPConnection:
|
|||
default_port = HTTP_PORT
|
||||
auto_open = 1
|
||||
debuglevel = 0
|
||||
# TCP Maximum Segment Size (MSS) is determined by the TCP stack on
|
||||
# a per-connection basis. There is no simple and efficient
|
||||
# platform independent mechanism for determining the MSS, so
|
||||
# instead a reasonable estimate is chosen. The getsockopt()
|
||||
# interface using the TCP_MAXSEG parameter may be a suitable
|
||||
# approach on some operating systems. A value of 16KiB is chosen
|
||||
# as a reasonable estimate of the maximum MSS.
|
||||
mss = 16384
|
||||
|
||||
def __init__(self, host, port=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT,
|
||||
source_address=None):
|
||||
|
@ -786,8 +778,9 @@ class HTTPConnection:
|
|||
|
||||
def connect(self):
|
||||
"""Connect to the host and port specified in __init__."""
|
||||
self.sock = self._create_connection((self.host,self.port),
|
||||
self.timeout, self.source_address)
|
||||
self.sock = self._create_connection(
|
||||
(self.host,self.port), self.timeout, self.source_address)
|
||||
self.sock.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
|
||||
|
||||
if self._tunnel_host:
|
||||
self._tunnel()
|
||||
|
@ -866,19 +859,9 @@ class HTTPConnection:
|
|||
self._buffer.extend((b"", b""))
|
||||
msg = b"\r\n".join(self._buffer)
|
||||
del self._buffer[:]
|
||||
# If msg and message_body are sent in a single send() call,
|
||||
# it will avoid performance problems caused by the interaction
|
||||
# between delayed ack and the Nagle algorithm. However,
|
||||
# there is no performance gain if the message is larger
|
||||
# than MSS (and there is a memory penalty for the message
|
||||
# copy).
|
||||
if isinstance(message_body, bytes) and len(message_body) < self.mss:
|
||||
msg += message_body
|
||||
message_body = None
|
||||
|
||||
self.send(msg)
|
||||
if message_body is not None:
|
||||
# message_body was not a string (i.e. it is a file), and
|
||||
# we must run the risk of Nagle.
|
||||
self.send(message_body)
|
||||
|
||||
def putrequest(self, method, url, skip_host=0, skip_accept_encoding=0):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue