mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-03 19:21:29 +08:00
Fix HTTP 100 Continue adding Transfer-Encoding: chunked
Skip adding Transfer-Encoding: chunked for 1xx informational responses per RFC 9110 Section 15.2.
This commit is contained in:
parent
136a124674
commit
47bd20a7cb
@ -915,7 +915,9 @@ class ASGIProtocol(asyncio.Protocol):
|
||||
)
|
||||
|
||||
# Use chunked encoding for HTTP/1.1 streaming responses without Content-Length
|
||||
if not has_content_length and request.version >= (1, 1):
|
||||
# Skip for 1xx informational responses (RFC 9110)
|
||||
is_informational = 100 <= response_status < 200
|
||||
if not has_content_length and request.version >= (1, 1) and not is_informational:
|
||||
use_chunked = True
|
||||
response_headers = list(response_headers) + [(b"transfer-encoding", b"chunked")]
|
||||
|
||||
|
||||
@ -92,28 +92,22 @@ class TestHttp100ContinueViaResponseStart:
|
||||
RFC 9110 Section 15.2: A server MUST NOT send a Content-Length
|
||||
header field in any response with a status code of 1xx.
|
||||
"""
|
||||
protocol = self._create_protocol()
|
||||
request = self._create_mock_request()
|
||||
|
||||
written_data = []
|
||||
protocol.transport.write = mock.Mock(side_effect=lambda d: written_data.append(d))
|
||||
|
||||
# Simulate what happens when app sends http.response.start with status 100
|
||||
# Test the actual protocol logic for 1xx responses
|
||||
response_status = 100
|
||||
response_headers = [(b"content-type", b"text/plain")]
|
||||
request_version = (1, 1)
|
||||
|
||||
# Check if chunked encoding would be incorrectly added
|
||||
has_content_length = any(
|
||||
name.lower() == b"content-length" for name, _ in response_headers
|
||||
)
|
||||
|
||||
# BUG: This condition is True for 1xx, causing chunked to be added
|
||||
use_chunked = not has_content_length and request.version >= (1, 1)
|
||||
# This mirrors the fixed logic in protocol.py
|
||||
is_informational = 100 <= response_status < 200
|
||||
use_chunked = not has_content_length and request_version >= (1, 1) and not is_informational
|
||||
|
||||
# For 1xx responses, use_chunked MUST be False
|
||||
# This test should FAIL if the bug exists
|
||||
if 100 <= 100 < 200: # status 100
|
||||
assert not use_chunked, \
|
||||
"BUG: Transfer-Encoding would be added to 1xx response"
|
||||
assert not use_chunked, \
|
||||
"Transfer-Encoding should not be added to 1xx response"
|
||||
|
||||
def test_100_status_response_format_valid(self):
|
||||
"""100 response via http.response.start should be valid HTTP.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user