We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Heya! I think I found a bug in gunicorn's handling of responses which were already chunked.
If a handler upstream to gunicorn:
Content-Length
Transfer-Encoding: chunked
<length>\r\n<data>\r\n
gunicorn wraps the already-chunked content in chunks, corrupting the data stream with erroneous framing.
is_chunked is used to turn on gunicorn's own chunking, but does not consider if the response is already chunked.
is_chunked
gunicorn/gunicorn/http/wsgi.py
Lines 286 to 301 in bacbf8a
A flask app which streams its own response like this. Works fine with other WSGI wrappers:
@some_blueprint.route('/stream', methods=['POST']) def stream(): r = Response(chunk_generator(), content_type='application/chunked-json') r.automatically_set_content_length = False r.direct_passthrough = True r.headers['Transfer-Encoding'] = 'chunked' return r def chunk_generator() -> Generator[bytes, None, None]: for x in range(50): c = wire_chunk('some bytes'.encode('utf-8')) yield c yield '0\r\n\r\n'.encode('utf-8') # Symbolizes end of stream def wire_chunk(data: bytes) -> bytes: data_len = len(data) return f'{data_len:x}'.encode('utf-8') + '\r\n'.encode('utf-8') + data + '\r\n'.encode('utf-8')
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Heya! I think I found a bug in gunicorn's handling of responses which were already chunked.
The issue
If a handler upstream to gunicorn:
Content-Length
Transfer-Encoding: chunked
<length>\r\n<data>\r\n
)gunicorn wraps the already-chunked content in chunks, corrupting the data stream with erroneous framing.
Suspected code
is_chunked
is used to turn on gunicorn's own chunking, but does not consider if the response is already chunked.gunicorn/gunicorn/http/wsgi.py
Lines 286 to 301 in bacbf8a
Repro steps
A flask app which streams its own response like this. Works fine with other WSGI wrappers:
The text was updated successfully, but these errors were encountered: