Search code examples
http2

HTTP/2: Does the server create a new stream to return to the client?


I learned that when client or server have data they want to send to each other they will use stream. Data will be split into Frames and sent on the same stream Identifiers. Client or server after receiving enough Fram containing data will reassemble into data.

I also know that the client will generate Stream Identifiers with odd numbers and the server will generate even numbers.

Question: With HTTP there will be request and response. Does the Response use the same Stream Identifiers?

Example: Client sends request to Server with stream Identifiers 1. The server receives the request and processes it. When the server returns the response to the client, will it create a new stream Identifiers is 2 or use the client's stream Identifiers 1 to return data to the client?

enter image description here


Solution

  • An HTTP/2 stream is the flow of frames for both a request and its correspondent response, so you can think of stream = request + response.

    When the server returns a response to a request, the response frames must use the same stream id as the request frames, because they belong to same stream.