summaryrefslogtreecommitdiffstats
path: root/Lib/http
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2013-01-02 21:10:47 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2013-01-02 21:10:47 (GMT)
commit90e477455873c2b701d5eb0bc751da7ac9510754 (patch)
treee616f7bea00a08d8bc58a0e623bfb038bdb3f597 /Lib/http
parentf42267642398be24049c6a618997c2ef1fe51b8a (diff)
downloadcpython-90e477455873c2b701d5eb0bc751da7ac9510754.zip
cpython-90e477455873c2b701d5eb0bc751da7ac9510754.tar.gz
cpython-90e477455873c2b701d5eb0bc751da7ac9510754.tar.bz2
Issue #16833: In http.client.HTTPConnection, do not concatenate the request headers and body when the payload exceeds 16 KB, since it can consume more memory for no benefit.
Patch by Benno Leslie.
Diffstat (limited to 'Lib/http')
-rw-r--r--Lib/http/client.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/Lib/http/client.py b/Lib/http/client.py
index 5e5b3a3..7db79b3 100644
--- a/Lib/http/client.py
+++ b/Lib/http/client.py
@@ -719,6 +719,14 @@ 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, strict=_strict_sentinel,
timeout=socket._GLOBAL_DEFAULT_TIMEOUT, source_address=None):
@@ -886,8 +894,11 @@ class HTTPConnection:
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.
- if isinstance(message_body, bytes):
+ # 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)