Search code examples
httptcphttp2

In HTTP/2, What's the relationship between req/resp, frame and TCP packet?


enter image description here

Image is from https://hpbn.co/http2/#streams-messages-and-frames.

I want to make sure I really understand what's going on, so here's my understanding:

  • a TCP packet may contain several frames, and they can belong to different streams.
  • a request or response is composed of one or more frames that belong to the same stream.
  • Physically there's no "stream", it's just a logical concept(Yeah I know each frame contains a stream ID).

Am I correct?


Solution

  • I believe everything you said is correct, but I'd clarify:

    • The main point is that a single TCP connection may contain frames from many different HTTP/2 streams, interleaved. The relationship to TCP packets is not important here - TCP packets are reassembled into TCP streams by your TCP stack, and should have no bearing on your understanding of HTTP/2.
    • The reason why that first point is important is that it is a huge step forward from HTTP/1, in which the TCP stream is "blocked" by any given request/response pair, since the response to the current request must be sent before any other ones. This is the multiplexing feature that unblocks a huge bottleneck of HTTP/1.
    • A request or response is called a message and yes, it's composed of one or more frames.
    • There is no physical HTTP/2 stream just like there is no physical TCP stream - it's a higher level concept/abstraction that is handled by the layer in question, which reassembles individual packets or frames into a stream, which makes it infinitely easier to deal with.

    Hope that helps.