Skip to content

βš™οΈ 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

TCP connection
 β”œβ”€β”€ Stream 1: Request A
 β”‚     β”œβ”€β”€ HEADERS
 β”‚     β”œβ”€β”€ DATA
 β”‚     └── END_STREAM
 β”œβ”€β”€ Stream 3: Request B
 β”‚     β”œβ”€β”€ HEADERS
 β”‚     β”œβ”€β”€ DATA
 β”‚     └── END_STREAM
 └── Stream 5: Request C

β†’ 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.:

ALPN extension: h2, http/1.1

If the server supports HTTP/2, it responds:

ALPN protocol: h2

πŸ§ͺ Lab 1 – Observe ALPN Negotiation

openssl s_client -connect www.google.com:443 -alpn h2

β†’ Look for:

ALPN protocol: h2

Try forcing HTTP/1.1:

curl -v --http1.1 https://www.google.com
curl -v --http2 https://www.google.com

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

  1. Client sends HEADERS (GET /).
  2. Server responds with HEADERS (200 OK).
  3. Server sends DATA frames (HTML).
  4. 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:

1
2
3
4
GET /index.html HTTP/1.1
Host: example.com
User-Agent: curl/8.0
Accept: */*

HTTP/2:

1
2
3
4
5
6
HEADERS frame:
  :method = GET
  :path = /index.html
  :scheme = https
  :authority = example.com
  (compressed binary form)

πŸ§ͺ Lab 2 – View Headers with HTTP/2

curl -v --http2 -o /dev/null -s -w '%{http_version}\n' https://nghttp2.org

β†’ Output: 2

Then use:

nghttp -nv https://nghttp2.org

β†’ 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

  1. Run:

    curl -v --http2 --parallel https://http2.golang.org/reqinfo
    

  2. Observe how multiple requests are served simultaneously on one connection (check Wireshark).

  3. Compare to HTTP/1.1:

curl -v --http1.1 --parallel https://http2.golang.org/reqinfo

β†’ 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

nghttp -ansv https://http2.golang.org/serverpush

β†’ You’ll see pushed resources listed with PUSH_PROMISE frames.

πŸ“˜ Section 8: Wireshark Analysis

πŸ§ͺ Lab 5 – Capture and Decode HTTP/2

  1. Start Wireshark, filter: tcp.port == 443.
  2. Visit https://nghttp2.org or https://www.google.com.
  3. In Protocol Preferences, enable:
    Analyze β†’ Enabled Protocols β†’ http2
    
  4. Inspect:

  5. ALPN negotiation in TLS handshake.

  6. HTTP/2 frames (SETTINGS, HEADERS, DATA).
  7. 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

  1. Use curl’s built-in timing:
    1
    2
    3
    4
    5
    curl -w "@- " -o /dev/null -s --http1.1 https://www.google.com <<'EOF'
    time_connect:  %{time_connect}s
    time_starttransfer:  %{time_starttransfer}s
    time_total:  %{time_total}s
    EOF
    

Repeat with --http2.

  1. 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:

curl -v --http1.1 https://example.com

Then check why HTTP/2 was not negotiated (e.g., missing h2 in server’s ALPN).

🧠 Knowledge Check

  1. What is multiplexing, and why does it improve performance?
  2. What is the purpose of HPACK?
  3. How does ALPN determine protocol version?
  4. What are frames and streams in HTTP/2?
  5. 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.