hip
hip copied to clipboard
Add support for Async and Sync Iterators as Request bodies
These two scripts should be allowed to bring us in line with Requests:
def sync_gen():
yield b"data"
async def async_gen():
yield b"data"
# ahip supports async and sync iterators
import ahip
import trio
http = ahip.PoolManager()
async def main():
await http.request("POST", "http://example.com", body=sync_gen())
await http.request("POST", "http://example.com", body=async_gen())
trio.run(main)
# 'hip' supports only sync
import hip
http = hip.PoolManager()
http.request("POST", "http://example.com", body=sync_gen())
Some notes:
- Treat both of these cases as errors if a redirect occurs, raise
UnrewindableBodyexception - shouldn't set
content-lengthsince length is not known until we drain the body, should betransfer-encoding: chunked
Related:
- https://github.com/python-trio/hip/issues/199
- https://github.com/python-trio/hip/issues/135