Bidirectional streaming #528
-
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.
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:
With
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. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
You're looking for the https://www.encode.io/httpcore/extensions/#network_stream That'll give you a read/write interface directly onto either the TCP connection (HTTP/1.1) or onto an individual HTTP/2 stream. I'd recommend that you start out by giving it a go from url = httpcore.URL(b"http", b"127.0.0.1", 8080, b"http://www.example.com")
with httpcore.stream("POST", url) as response:
network_stream = response.extensions["network_stream"]
... We documented it for
It'd be useful to understand your use-case more clearly here? Also please do please let us know how you get on with this, it'd be great to get more feedback on our network stream interface. |
Beta Was this translation helpful? Give feedback.
-
@tomchristie I ended up simply abandoning HTTP, and used websockets instead. Still have some trouble managing backpressure, but it seems to be doing better than HTTP. |
Beta Was this translation helpful? Give feedback.
You're looking for the
network_stream
extension...https://www.encode.io/httpcore/extensions/#network_stream
That'll give you a read/write interface directly onto either the TCP connection (HTTP/1.1) or onto an individual HTTP/2 stream.
I'd recommend that you start out by giving it a go from
httpcore
directly, and then switch up to using it withhttpx
once you're confident you've got everything working...We documented it for
"CONNECT"
method requests and requests using theUpgrade
header. It should als…