Skip to content

Bidirectional streaming #527

Description

@benblack769

Is concurrent bidirectional streaming supported by httpcore? This is a key feature of HTTP/2.0 that I was hoping httpcore/httpx would support, but it does not seem like it is.

I wrote an httpx client to handle a bidirectional streaming http server, one that sends body request packets back at the same time it receives body response packets.


    content_list = []
    async with httpx.AsyncClient(http1=False, http2=True) as client:
        async with client.stream(method="POST", url=f"http://127.0.0.1:8000/bidirectional", content=generate_chunks(), timeout=10.) as response:
            async for chunk in response.aiter_raw():
                   ....

However, I found that this logic in httpcore https://github.com/encode/httpcore/blob/master/httpcore/_async/http2.py#L110 where it awaits for the body to send before returning the Response ensures that responses cannot be accepted by the client at the same time as requests are sent.

One incredibly naive solution I found is to simply replace:

await self._send_request_body(request=request, stream_id=stream_id)

With

asyncio.get_event_loop().create_task(self._send_request_body(request=request, stream_id=stream_id))

This way, the body is sent concurrently with the response being received.

Is this something that you hope to support? If so, then I can take a look in the code and try to find a better solution.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions