Backend Development 12 min read

Understanding HTTP/2 Implementation in Go's HTTP Server

This article provides a comprehensive overview of HTTP/2, explaining its binary framing, multiplexing, and the various frame types such as DATA, HEADERS, PRIORITY, RST_STREAM, SETTINGS, PUSH_PROMISE, PING, GOAWAY, WINDOW_UPDATE, and CONTINUATION, with specific focus on how Go's HTTP server implements these features.

360 Tech Engineering
360 Tech Engineering
360 Tech Engineering
Understanding HTTP/2 Implementation in Go's HTTP Server

The article introduces the implementation of HTTP/2 in Go's HTTP server, noting that HTTP/2 retains HTTP semantics while introducing binary framing, multiplexing, header compression, and server push, which require deeper understanding to leverage new features.

It explains the core concepts of HTTP/2: frames (the smallest communication unit), messages (collections of frames), and streams (bidirectional byte streams), and how they relate within a single TCP connection.

Binary framing is detailed with a diagram of the frame structure, followed by explanations of each field: Length, Type, Flags, R (reserved), and Stream Identifier, including size limits and configuration via SETTINGS.

+-----------------------------------------------+
|               Length (24)                   |
+---------------+---------------+---------------+
|   Type (8)    |   Flags (8)   |
+-+-------------+---------------+-------------------------------+
|R|            Stream Identifier (31)          |
+=+=============================================================+
|               Frame Payload (0...)            ...
+---------------------------------------------------------------+

The article then describes each frame type:

DATA Frame (type=0x0) : carries binary payload data, with optional padding and the END_STREAM flag indicating stream termination.

HEADERS Frame (type=0x1) : initiates a stream and carries HTTP header fields, with optional priority information.

PRIORITY Frame (type=0x2) : sets stream priority, using dependency and weight fields.

RST_STREAM Frame (type=0x3) : abruptly terminates a stream with an error code.

SETTINGS Frame (type=0x4) : configures connection parameters such as header table size, enable push, max concurrent streams, etc., and includes an ACK flag.

PUSH_PROMISE Frame (type=0x5) : used by the server to initiate server push, indicating a promised stream.

PING Frame (type=0x6) : measures round‑trip time and checks connection liveness, containing opaque data and an ACK flag.

GOAWAY Frame (type=0x7) : gracefully shuts down a connection, indicating the last processed stream and an error code.

WINDOW_UPDATE Frame (type=0x8) : adjusts flow‑control windows for streams or the connection.

CONTINUATION Frame (type=0x9) : continues header block fragments when they do not fit in a single HEADERS or PUSH_PROMISE frame.

Multiplexing is highlighted as a key advantage of HTTP/2, allowing multiple concurrent streams over a single TCP connection, eliminating head‑of‑line blocking and reducing latency.

The article concludes that while the concepts are dense, understanding them is essential for utilizing HTTP/2 features in Go applications.

Reference materials include the HTTP/2 RFC7540 and Google's Web Performance guide.

BackendGoProtocolHTTP/2Multiplexingframes
360 Tech Engineering
Written by

360 Tech Engineering

Official tech channel of 360, building the most professional technology aggregation platform for the brand.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.