Skip to main content

5. Streams and Multiplexing

A "stream" is an independent, bidirectional sequence of frames exchanged between the client and server within an HTTP/2 connection.

Key Characteristics

  • Streams can be established and used unilaterally or shared by either client or server
  • Streams can be closed by either endpoint
  • Order of frames sent on a stream is significant
  • Streams are identified by an integer (Stream Identifier)
  • Stream Identifiers initiated by clients are odd; by servers are even
  • Stream ID 0 is reserved for connection control messages

5.1 Stream States

Streams transition through various states during their lifetime:

                         +--------+
send PP | | recv PP
,--------| idle |--------.
/ | | \
v +--------+ v
+----------+ | +----------+
| | | send H / | |
,------| reserved | | recv H | reserved |------.
| | (local) | | | (remote) | |
| +----------+ v +----------+ |
| | +--------+ | |
| | recv ES | | send ES | |
| send H | ,-------| open |-------. | recv H |
| | / | | \ | |
| v v +--------+ v v |
| +----------+ | +----------+ |
| | half | | | half | |
| | closed | | send R / | closed | |
| | (remote) | | recv R | (local) | |
| +----------+ | +----------+ |
| | | | |
| | send ES / | recv ES / | |
| | send R / v send R / | |
| | recv R +--------+ recv R | |
| send R / `----------->| |<-----------' send R / |
| recv R | closed | recv R |
`----------------------->| |<----------------------'
+--------+

5.2 Flow Control

HTTP/2 provides flow control using WINDOW_UPDATE frames to prevent sender from overwhelming receiver.

Principles:

  • Flow control is specific to a connection
  • Flow control is directional
  • Flow control is credit-based
  • Initial flow-control window size is 65,535 octets
  • Flow control applies to DATA frames

5.3 Stream Priority

Clients can assign a priority to streams using PRIORITY frames or HEADERS frames with priority information.