hip icon indicating copy to clipboard operation
hip copied to clipboard

Add support for Async and Sync Iterators as Request bodies

Open sethmlarson opened this issue 5 years ago • 0 comments

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 UnrewindableBody exception
  • shouldn't set content-length since length is not known until we drain the body, should be transfer-encoding: chunked

Related:

  • https://github.com/python-trio/hip/issues/199
  • https://github.com/python-trio/hip/issues/135

sethmlarson avatar May 12 '20 23:05 sethmlarson