The messages in HTTP/2 are sent in binary frames. What are the frame format, frame size, and frame types like? This article will summarize the frame format and the ten types of frames.
![HTTP/2](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-950c70vpl7.png)
The frame format consists of a 9-byte frame header and a frame data payload; the frame header consists of a 3-byte frame length, a 1-byte frame type, a 1-byte flag, and a 4-byte stream identifier (including a 1-bit reserved R space).
The frame length is represented by 24 bits, equivalent to 3 bytes in size. The value ranges between 2^14 (16,384) and 2^24-1 (16,777,215); it can be set by the receiver using SETTINGS_MAX_FRAME_SIZE.
The frame type is represented by an 8-bit byte that describes the frame’s format and semantics. The specific types of frames are described below.
The flags are represented by an 8-bit byte. For example: The END_HEADERS flag indicates the end of header data transmission; END_STREAM indicates the end of unidirectional data transmission.
R is a 1-bit reserved field, undefined, ending with 0x0.
The stream identifier is represented by 31 bits, with an upper limit of 2^31. The receiver can assemble based on the stream identifier; frames within the same stream must be ordered, so the receiver can concatenate streams based on stream IDs to form ordered streams. Furthermore, streams initiated by the client use odd identifiers, while streams initiated by the server use even identifiers. Because stream identifiers are used, the receiver can order concurrent streams together, enabling multiplexing.
The payload of transmitted data is determined by the frame’s type.
![HTTP/2](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-91a8jz0xkf.jpeg)
Data frames mainly store HTTP/2 messages, the specific format is shown in the diagram below:
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-oj50lqpgve.png)
Padding: 8-bit padding byte, padding bytes can change the size of DATA frames and provide security features.
Pad Length: Length of the padding bytes; when PADDED is true, it indicates the presence of padding bytes.
Data: The data being transmitted.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-s5y0a0t5xw.jpeg)
The structure of the Header frame is shown in the diagram below:
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-9m5pmcep4x.png)
Pad Length: Length of the padding bytes, with the same meaning as the Data frame mentioned above.
E: Indicates whether the stream is exclusive. It has a value only when PRIORITY is set.
Stream Dependency: The stream upon which another stream depends. It has a value only when PRIORITY is set.
Weight: Stream priority weight. It has a value only when PRIORITY is set.
Header Block Fragment: A fragment of the header block.
Padding: Length of the padding bytes.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-kkjkdi633d.jpeg)
The format of the send stream’s priority, with meanings of various fields and packet capture screenshots in the Header frame.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-rq46x36kku.png)
Used to terminate a stream in case of errors or cancellations.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-95027ef9yc.png)
Error Code: 32-bit error code indicating the reason for the error.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-5qjkaqo7v7.jpeg)
Used to convey configuration parameters between connection endpoints.
The SETTINGS frame’s ACK flag set to 0 indicates use by the peer’s SETTINGS frame; ACK not 0 indicates a FRAME_SIZE_ERROR connection error.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-bajasgiq7q.png)
SETTINGS_HEADER_TABLE_SIZE: Notifies the receiver of the maximum size of the header decoding table (for decoding header blocks).
SETTINGS_ENABLE_PUSH: Initial value of 1 indicates server-initiated push is allowed; 0 indicates it is disallowed.
SETTINGS_MAX_CONCURRENT_STREAMS: Maximum number of concurrent streams (for sender).
SETTINGS_INITIAL_WINDOW_SIZE: Stream window size, default is 65535.
SETTINGS_MAX_FRAME_SIZE: Frame payload size.
SETTINGS_MAX_HEADER_LIST_SIZE: Maximum size of the header list.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-hs5ar9ao9m.jpeg)
Frames pushed by the server to the client that the client can reject with RST_STREAM.
R in the diagram is a reserved bit.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-sg1ra5yzgf.png)
Heartbeat detection helps measure round-trip time to ensure the connection is normal.
Setting the ACK flag to 0, i.e., false, indicates a response to a PING frame; 1, i.e., True, indicates the PING frame itself.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-fpaimsm4a8.png)
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-xqlf3fvgyx.jpeg)
Used for closing the connection or reporting errors, it allows for stopping the acceptance of new streams while completing the processing of prior streams.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-80rnpvuvs0.png)
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-ghchektdtd.jpeg)
Used for flow control of connections and streams.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-ya42knsdkg.png)
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-4it7lz00w7.jpeg)
CONTINUATION is a type of frame used to continue transmitting header block fragments. It is typically used when the header block is relatively large, continuing transmission following HEADERS, PUSH_PROMISE, and CONTINUATION frames.
![](https://www.ids-sax2.com/wp-content/uploads/picture/ask-qcloudimg-com-ib9xudx0l2.png)
Through the organization and inspection of binary frame contents, various frames of HTTP/2 communication become more familiar, allowing users to understand what operations the communicating parties are performing based on the types of frames. Feel free to interact with the author and discuss together.