Appendix A. HTTP/2 Frames

This appendix is a quick reference for the HTTP/2 framing layer. Each section includes the frame type number, the binary layout for the frame, a description of the frame, and a list of flags specific to that frame.

The Frame Header

As described in Chapter 5, each frame starts with the same nine bytes:

Frame Header

See Table 5-1 for a description of each field.

DATA

DATA frames contain arbitrary sequences of octets. This is a fancy way of saying these frames contain the requested/sent objects. Object data is split up across one or more frames depending on the maximum frame length. The padding length field and the padding itself are conditionally included to hide the size of the message for security purposes:

Data Frame

DATA Frame Fields

Name Length Description

Pad Length

1 byte

Indicates the length of the padding field. Will only be present if the PADDED flag is set in the frame header.

Data

Variable

The content of the frame.

Padding

Variable

Length set by the Pad Length field. All bytes are set to zero.

DATA Frame Flags

Name Bit Description

END_STREAM

0x1

Indicates this is the frame in the stream

PADDED

0x8

Indicates that the Pad Length and Padding fields are used

HEADERS

HEADERS frames are used to start streams and send message headers to an endpoint:

Headers Frame

HEADERS Frame Fields

Name Length Description

Pad Length

1 byte

Indicates the length of the padding field. Will only be present if the PADDED flag is set in the frame header.

E

1 bit

Indicates whether the stream dependency is exclusive. Only present if the PRIORITY flag is set.

Stream Dependency

31 bits

Indicates which stream this stream is dependent on, if any. Only present if the PRIORITY flag is set.

Weight

1 byte

Indicates the relative priority of the stream. Only present if the PRIORITY flag is set.

Header Block Fragment

Variable

The headers for the message.

Padding

Variable

Length set by the Pad Length field. All bytes are set to zero.

HEADERS Frame Flags

Name Bit Description

END_STREAM

0x1

Indicates this is the frame in the stream.

END_HEADERS

0x4

Indicates this is the last HEADERS frame in the stream. If this is flag not set it implies a CONTINUATION frame is next.

PADDED

0x8

Indicates that the Pad Length and Padding fields are used.

PRIORITY

0x20

When set it indicates that the E, Stream Dependency, and weight fields are used.

PRIORITY

The PRIORITY frame is sent to indicate the priority of the stream. It can be sent multiple times and will change the advised priority if previously set:

PRIORITY Frame

PRIORITY Frame Fields

Name Length Description

E

1 bit

Indicates whether the stream dependency is exclusive.

Stream Dependency

31 bits

Communicates the stream this stream is dependent on, if any.

Weight

1 byte

Indicates the relative priority of the stream.

A PRIORITY frame does not have any frame-specific flags.

RST_STREAM

RST_STREAM is used by either end of a stream to terminate the stream immediately. This is usually in response to an error condition.

The Error Code field in the frame is used to communicate the reason for the reset. See section 7 of RFC 75401 for a listing of those fields:

RST_STREAM Frame

SETTINGS

The SETTINGS frame is a sequence of key/value pairs. The number of pairs is defined by the frame length divided by the individual setting length (six):

SETTINGS Frame

SETTINGS Parameters

Name ID Default Description

SETTINGS_HEADER_TABLE_SIZE

0x1

4096

Changes the maximum size of the header table used for HPACK.

SETTINGS_ENABLE_PUSH

0x2

1

If set to 0 the peer may not send a PUSH_PROMISE frame.

SETTINGS_MAX_CONCURRENT_STREAMS

0x3

No limit

Indicates the maximum number of streams that the sender will allow.

SETTINGS_INITIAL_WINDOW_SIZE

0x4

65353

Indicates the sender’s initial window size for flow control.

SETTINGS_MAX_FRAME_SIZE

0x5

16384

Indicates the maximum frame size the sender is willing to receive. This value must be between this initial value and 16,777,215 (224-1).

SETTINGS_MAX_HEADER_LIST_SIZE

0x6

No limit

This setting is used to advise a peer of the maximum size of the header the sender is willing to accept.

When an endpoint receives and processes a SETTINGS frame, it must return a SETTINGS frame with the ACK flag (0x1) set in the frame header. This is the only flag defined for the SETTINGS frame. In this way the sender gets acknowledgment that the endpoint received the new SETTINGS and should be abiding by them.

PUSH_PROMISE

The PUSH_PROMISE frame is sent by a server to indicate to the client that it is about to send an object that the client has not explicitly requested. It is effectively the complement to a HEADERS frame sent by the client:

PUSH_PROMISE Frame

PUSH_PROMISE Frame Fields

Name Length Description

Pad Length

1 byte

Indicates the length of the padding field. Will only be present if the PADDED flag is set in the frame header.

R

1 bit

A single reserved bit. Do not set this or else.

Promised Stream ID

31 bits

Communicates the stream ID that the sender will use (will always be an even number as this is coming from the server by definition).

Header Block Fragment

Varible

The pushed headers for the message.

Padding

Variable

Length set by the Pad Length field. All bytes are set to zero.

PUSH_PROMISE Frame Flags

Name Bit Description

END_HEADERS

0x4

Indicates this is the last HEADERS frame in the stream. If this is not set it implies a CONTINUATION frame is next.

PADDED

0x8

Indicates that the Pad Length and Padding fields are used.

PING

The PING frame is intended to be used to measure the round-trip time between endpoints. The frame has one flag, ACK (0x1). When an endpoint receives a PING frame without an ACK sent, it must send a PING frame back with the ACK flag set and the same opaque data. It should be noted that PING frames are not associated with any particular stream (they are connection level), and thus should have their stream identifier set to 0x0:

PING Frame

GOAWAY

The GOAWAY frame is used to gracefully shut down a connection. This is a connection-level frame and must be sent on stream identifier 0x0. By sending a GOAWAY frame, the endpoint is able to clearly define to the receiver what it has and has not received and what problem (if any) may have contributed to the GOAWAY. In the case of a problem, the error code will be set to one of the codes defined in section 7 of RFC 7540, and the Last Stream ID will be set to the highest stream ID that was processed. If there has been no error but the endpoint is about to tear down the connection (browser tab closed, connection timer exceeded, etc.), it sends the NO_ERROR (0x0) code and sets the Last Stream ID to 231-1:

GOAWAY Frame

GOAWAY Frame Fields

Name Length Description

R

1 bit

A single reserved bit.

Last Stream ID

31 bits

The highest number stream ID the GOAWAY sender has received/processed. By sending this the receiver knows precisely what the sender has and has not received.

Error Code

4 bytes

The h2-defined error code or NO_ERROR code in the case of a successful shutdown.

Additional Debug Data

Variable

Opaque data the sender may send to indicate more information into the state or any problems.

WINDOW_UPDATE

The WINDOW_UPDATE frame is used for stream flow control. Sending a WINDOW_UPDATE frame to a peer tells that peer how many bytes the sender is willing to accept at that time. Flow control can apply to individual streams or all streams on a connection (Stream ID 0x0). Note that a WINDOW_UPDATE on a specific stream applies to the connection-level flow control as well:

WINDOW_UPDATE Frame

WINDOW_UPDATE Frame Fields

Name Length Description

R

1 bit

A single reserved bit.

Window Size Increment

31 bits

The number of bytes to increase the current window by.

The WINDOW_UPDATE frame has no frame-specific flags.

CONTINUATION

The CONTINUTATION frame contains additional headers from a previous HEADERS, PUSH_PROMISE, or CONTINUATION frame:

CONTINUATION Frame

CONTINUATION Frame Fields

Name Length Description

Header Block Fragment

Variable

See HEADERS frame for a description.

CONTINUATION Frame Flags

Name Bit Description

END_HEADERS

0x4

Indicates this is the last HEADERS frame in the stream. If this is not set it implies another CONTINUATION frame is next.