swagger-api / swagger-api/swagger-codegen
[Python] tornado client does not support chunked responses
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
The python tornado client does not support chunked/streaming responses. When _preload_content is True the entire response body is read. When _preload_content is False the response body is still read but the raw tornado request is returned instead (probably a bug).
I think the expected behavior should be similar to using urllib3: When _preload_content=True the response body should not be be read, allowing the caller to call read_chunk on the response object, and presumably handle the deserialization of the chunks themselves.
Suggest a fix/enhancement
Unfortunately, for tornado to support reading streaming responses you must provide a streaming_callback to the request which is called whenever a chunk arrives off the socket. There is no other way way to prevent the client from attempting to read the entire response body. Allowing the caller to specify a callback doesn't really mesh well with the way the APIClient works, so it likely requires some trickery to make it work (and a bit of buffering).
FWIW, the python asyncio client probably has a similar issue where the response body is always read, though the fix is probably simpler since aiohttp doesn't require a callback, but I've not looked into this much.
I have a PR for this in progress.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the Python Tornado client and APIClient handling of _preload_content, comparing the behavior described with urllib3 and the asyncio client. Trace how Tornado requests consume response bodies and how a streaming callback could be buffered. Done means chunked responses can be consumed incrementally without forcing the full body read, while preserving the expected deserialization behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100