fix: use smaller buffer in finish_body for faster timeout

Reduce buffer size from 8192 to 1024 bytes when discarding unread
body data, allowing timeouts to trigger more quickly on slow or
stalled connections.
This commit is contained in:
Benoit Chesneau 2026-01-23 14:46:40 +01:00
parent 66963367f3
commit f95ac41b8f
2 changed files with 4 additions and 4 deletions

View File

@ -36,9 +36,9 @@ class Parser:
"""
if self.mesg:
try:
data = self.mesg.body.read(8192)
data = self.mesg.body.read(1024)
while data:
data = self.mesg.body.read(8192)
data = self.mesg.body.read(1024)
except ssl.SSLWantReadError:
# SSL socket has no more application data available
pass

View File

@ -1443,7 +1443,7 @@ class TestFinishBodySSL:
parser.finish_body() # Should not raise
# Verify body.read was called
mock_body.read.assert_called_once_with(8192)
mock_body.read.assert_called_once_with(1024)
def test_finish_body_reads_all_data_before_ssl_error(self):
"""Test that finish_body() reads all available data before SSLWantReadError."""
@ -1513,4 +1513,4 @@ class TestFinishBodySSL:
parser.finish_body()
# Verify body.read was called once and returned empty
mock_body.read.assert_called_once_with(8192)
mock_body.read.assert_called_once_with(1024)