βοΈ Stage 4: Deep Dive into HTTP/2¶
π― Learning Objectives¶
By the end of this stage, you will be able to:
- Explain why HTTP/2 was created and how it improves HTTP/1.1.
- Describe binary framing, streams, frames, and multiplexing.
- Understand HPACK header compression.
- Identify ALPN negotiation in TLS.
- Capture and interpret HTTP/2 sessions in Wireshark and using command-line tools.
- Troubleshoot performance or compatibility issues between HTTP/1.1 and HTTP/2.
π Suggested Duration¶
1.5 weeks (8β10 hours total) - 4h theory - 4β6h labs and captures
π Section 1: Why HTTP/2 Exists¶
π§ Background¶
HTTP/1.1 had major limitations: - Each TCP connection handled one request at a time. - Multiple requests required multiple TCP connections (usually 6 per domain). - Head-of-line blocking (one slow request blocked the rest). - Repeated headers increased bandwidth use.
π§© HTTP/2 Goals¶
- Reduce latency
- Increase parallelism (multiplexing)
- Compress headers (HPACK)
- Maintain full backward compatibility with HTTP semantics
π Section 2: HTTP/2 Architecture Overview¶
π§ Key Concepts¶
- Binary Framing Layer β all data exchanged as frames, not text.
- Streams β bidirectional logical channels within a single TCP connection.
- Messages β groups of frames representing one request/response.
- Frames β smallest unit of communication (e.g., HEADERS, DATA, SETTINGS).
π§© Visualization¶
β Multiple streams share the same TCP connection = multiplexing.
π Analogy¶
Think of HTTP/2 like a multi-lane highway inside one TCP tunnel. Each stream is a car using its lane β no longer waiting for others to finish.
π Section 3: ALPN Negotiation (TLS Layer)¶
π§ Concept¶
HTTP/2 is negotiated over TLS using ALPN (Application-Layer Protocol Negotiation). During the TLS handshake, the client advertises supported protocols, e.g.:
If the server supports HTTP/2, it responds:
π§ͺ Lab 1 β Observe ALPN Negotiation¶
β Look for:
Try forcing HTTP/1.1:
Compare connection setup output.
π Section 4: HTTP/2 Frames and Streams¶
π§ Common Frame Types¶
| Frame Type | Description |
|---|---|
| HEADERS | Contains compressed headers for a request or response |
| DATA | Carries payload (body) |
| SETTINGS | Negotiates connection parameters |
| PRIORITY | Sets stream dependencies |
| RST_STREAM | Cancels a stream |
| WINDOW_UPDATE | Controls flow (for congestion management) |
| PING | Measures latency or checks connection health |
π§© Example Flow¶
- Client sends HEADERS (GET /).
- Server responds with HEADERS (200 OK).
- Server sends DATA frames (HTML).
- END_STREAM flag marks completion.
π Section 5: HPACK β Header Compression¶
π§ Concept¶
- HTTP/1.1 sent the same headers repeatedly (e.g.,
User-Agent,Host). - HTTP/2 uses HPACK to compress headers efficiently using:
- Static table of common headers.
- Dynamic table that grows as session progresses.
- This saves bandwidth and reduces latency.
π§© Example¶
HTTP/1.1:
HTTP/2:
π§ͺ Lab 2 β View Headers with HTTP/2¶
β Output: 2
Then use:
β Youβll see HEADERS and DATA frames decoded (requires nghttp package).
π Section 6: Multiplexing and Flow Control¶
π§ Concepts¶
- Multiple requests share the same TCP connection.
- Flow control prevents a single stream from monopolizing bandwidth.
- Window size adjusted via WINDOW_UPDATE frames.
π§ͺ Lab 3 β Demonstrate Multiplexing¶
-
Run:
-
Observe how multiple requests are served simultaneously on one connection (check Wireshark).
-
Compare to HTTP/1.1:
β HTTP/1.1 opens multiple TCP connections.
π Section 7: Server Push (Optional Feature)¶
π§ Concept¶
HTTP/2 allows servers to push resources (e.g., CSS, JS) before the client asks. Useful for performance, but often disabled now (replaced by preload in HTTP/3).
π§ͺ Lab 4 β Observe Server Push¶
β Youβll see pushed resources listed with PUSH_PROMISE frames.
π Section 8: Wireshark Analysis¶
π§ͺ Lab 5 β Capture and Decode HTTP/2¶
- Start Wireshark, filter:
tcp.port == 443. - Visit
https://nghttp2.orgorhttps://www.google.com. - In Protocol Preferences, enable:
-
Inspect:
-
ALPN negotiation in TLS handshake.
- HTTP/2 frames (SETTINGS, HEADERS, DATA).
- Multiplexed stream IDs.
π§© Tip¶
-
- Stream IDs: odd numbers = client-initiated, even = server-initiated. The βFollow TCP Streamβ view wonβt show plaintext (itβs binary).
π Section 9: HTTP/1.1 vs HTTP/2 Comparison¶
| Feature | HTTP/1.1 | HTTP/2 |
|---|---|---|
| Format | Text-based | Binary |
| Multiplexing | β One per connection | β Many per connection |
| Header Compression | β None | β HPACK |
| Server Push | β | β |
| Negotiation | Implicit | Via ALPN |
| Security | Optional | TLS required (in browsers) |
π§ͺ Lab 6 β Compare Latency¶
- Use
curlβs built-in timing:
Repeat with --http2.
- Compare results β HTTP/2 often has slightly faster total times on modern servers.
π Section 10: Troubleshooting HTTP/2¶
| Symptom | Cause | Diagnostic |
|---|---|---|
| Falls back to HTTP/1.1 | ALPN mismatch | Check TLS handshake for h2 |
| Stream resets | Flow control or protocol error | Wireshark: RST_STREAM |
| Mixed content issues | HTTP/2 always requires HTTPS | Ensure all subresources use HTTPS |
| Poor performance | Single connection overload | Check server SETTINGS and window sizes |
π§ͺ Lab 7 β ALPN Failure Simulation¶
Force HTTP/1.1:
Then check why HTTP/2 was not negotiated (e.g., missing h2 in serverβs ALPN).
π§ Knowledge Check¶
- What is multiplexing, and why does it improve performance?
- What is the purpose of HPACK?
- How does ALPN determine protocol version?
- What are frames and streams in HTTP/2?
- What changed between HTTP/1.1βs pipelining and HTTP/2βs multiplexing?
π Stage 4 Completion Outcome¶
You should now be able to: β Explain the binary framing model of HTTP/2. β Capture and interpret HTTP/2 handshakes and frames. β Use nghttp and curl to test HTTP/2 behavior. β Identify performance benefits and troubleshooting steps. β Understand how HTTP/2 builds on TLS with ALPN negotiation.