-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
HTTP/2: Add support for multiple streams and response streaming API #3476
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Thank you for starting this! I haven't looked at the code yet, only at your original description.
We should try to work on as small units of work as possible. If the existing issues don't work well, we can create new ones with a different split. That said, yes, we need to agree on the API itself.
Before we move forward with this, I'd like to have feedback from @sethmlarson on this HTTP2Stream class.
We need to keep the existing APIs. In other words, we need request() to return an HTTP2Response. When created, this response class can take ownership of an existing HTTP2Stream. |
Thanks for the reply! @pquentin
The existing
You are right, I should split up the work. I merged them because it was easier to test things out after everything was in-place. Also, I suggest the following changes to the existing issues:
This also means that issue in 1 is more work and of higher priority than issue in 2 and 3, mainly because a lot of stuff for 2 and 3 gets done in 1. Maybe the bounties should be readjusted as well! |
Being brief: I was imagining a one-to-one mapping of HTTP2Connection to stream ID and then relying on a global registry of sockets/HTTPStream-like objects so that we can continue using the existing |
So, in this approach will there will be one request active at a time in a connection. Since, each stream handles one request and its associated response. |
@hold7door Correct! That's already the case for HTTP/1.1 since we don't support pipe-lining. |
@sethmlarson I was wondering about how the multiplexing for HTTP/2 will look like in your design? Is it something like, one TCP connection/Socket is associated with multiple HTTP2Connection object. Also, where will the socket data(h2 events) be handled? |
@mrdaybird Multiplexing is handled by the HTTPSConnectionPool, similar to how you need to use this interface for multiplexing in HTTP/1.1.
Socket data and queues of events would be handled in the global HTTP2Stream/socket registry. HTTP2Connections only handle events and exceptions. |
Fixes #3300, Fixes #3294 Fixes #3301
Firstly, this PR is not complete, still I have put it up to get the discussion started.
This PR tries to achieve the following:
HTTP2Connection
. (solves Allow HTTP/2 connection and socket to be re-used for future requests #3301)read
andstream
. Add support for streaming HTTP/2 responses #3300I have merged these things together into because they are kind of interdependent and gives an idea about the whole picture, like how the API will look like.
Changes proposed by this PR ⇒
HTTP2Stream
, which manages the state of a stream. (similar to idea begin by @pquentin in Move response body handling into HTTP2Response #3294)HTTP2Connection
is now associated with multiple streams, the methodsputrequest
,endheaders
,send
andgetresponse
only have meaning in context of a stream. So, I suggest they should not be part of public API. Thus,putrequest
is changed to_putrequest
+ a newstream_id
parameterendheaders
is changed to_endheaders
+ a newstream_id
parametersend
is changed to_send_stream
+ a newstream_id
parametergetresponse
is removed, and moved toHTTP2Stream
_read_stream
that reads from socket and handles h2 eventsTo give you a little sneak peek, here is a working example of sending two request using single
HTTP2Connection
(HTTP/2 is awesome!) ⇒Important thing to note is that 1.
request
returns aHTTP2Stream
and 2.getresponse
needs to be called on theHTTP2Stream
to get aHTTP2Response
TODO:
read
methodstream
method@pquentin @sethmlarson
Since there are several substantial changes, therefore before moving on with this PR, I wanted to know your opinion of it!
If you want my explanation for any design/code decisions, please ask!