4.3.25 · D4 · HinglishComputer Networks

ExercisesHTTP - 2 — multiplexing, header compression (HPACK), server push

2,887 words13 min read↑ Read in English

4.3.25 · D4 · Coding › Computer Networks › HTTP - 2 — multiplexing, header compression (HPACK), server

Shuru karne se pehle, ek shared vocabulary anchor taaki koi bhi symbol bina explanation ke na aaye.

Figure — HTTP - 2 — multiplexing, header compression (HPACK), server push

Level 1 — Recognition

L1.1

Q. Ek frame header 9 bytes ka hota hai. Iske andar pack hue paanch fields list karo aur har field ki bit-width batao.

Recall Solution

Framing spec se, 9 bytes = 72 bits aise split hote hain:

  • Length — 24 bits
  • Type — 8 bits
  • Flags — 8 bits
  • R (reserved) — 1 bit
  • Stream ID — 31 bits

Check: bits bytes. ✅

L1.2

Q. Client-initiated streams kis parity ka Stream ID use karte hain, aur server-pushed streams kaun si use karte hain? Ye rule exist kyon karta hai?

Recall Solution

Client streams odd IDs use karte hain (1, 3, 5, …); server-pushed streams even IDs use karte hain (2, 4, 6, …). Kyon: dono sides ek hi connection par streams open karti hain. Agar dono ek hi pool se pick kar sakti, toh do independent choosers same number pick kar sakte — collision. Odd/even mein split karna ek zero-coordination tarika hai jo guarantee karta hai ki dono kabhi clash nahi karenge.

L1.3

Q. Har frame type ko uske kaam se match karo: HEADERS, DATA, PUSH_PROMISE, RST_STREAM.

Recall Solution
  • HEADERS — (HPACK-encoded) header block carry karta hai jo ek message shuru karta hai.
  • DATA — body bytes carry karta hai.
  • PUSH_PROMISE — us stream ko announce karta hai jise server push karna chahta hai, ek even Stream ID reserve karte hue.
  • RST_STREAM — connection ko touch kiye bina ek stream ko abruptly cancel karta hai.

Level 2 — Application

L2.1

Q. Default max frame payload bytes hai. Exactly kitne bytes hote hain, aur itna low cap kyon rakhte hain jabki Length field tak express kar sakta hai?

Recall Solution

bytes ( KiB). Length field could bytes tak hold karta, lekin default cap deliberately choti rakhi gayi hai. Kyon: agar ek frame bahut bada ho sakta, toh use bhejna single TCP connection ko lambe samay ke liye hog kar leta — wohi head-of-line stall wapas aa jaata jise multiplexing khatam karne ke liye hai. 16 KiB cap rakhe se doosre streams ke frames beech mein slip kar sakte hain.

L2.2

Q. Integer ko 5-bit prefix use karke HPACK prefix-integer encoding mein encode karo. Kitne bytes lagte hain?

Recall Solution

Rule: agar toh ko seedha bits mein store karo. Yahan , toh . Kyunki , hum bas ko 5 bits mein likhte hain. Us byte ke 3 high bits HPACK flag bits hain (woh representation type mark karte hain). Ek byte total. Koi continuation nahi chahiye.

L2.3

Q. Integer ko 5-bit prefix mein encode karo. Byte sequence do.

Recall Solution

aur , toh prefix overflow karta hai.

  1. Prefix value emit karo (sab 5 bits set).
  2. Remainder .
  3. ko 7-bit groups mein split karo, low group pehle, high bit = "aur aayenge":
    • , toh pehla continuation byte .
    • Agla , toh final byte (high bit clear = "last").

Byte sequence: 31, 154, 10 — teen bytes.

L2.4

Q. Static table entry :method GET index 2 par hai. Is header ki fully-indexed HPACK representation likho aur uska size batao.

Recall Solution

Fully indexed = leading 1 bit, phir index ek 7-bit prefix mein. Index , toh seedha fit ho jaata hai. Byte hai 1 ke baad 0000010: Ek byte poori :method: GET line encode kar deta hai.


Level 3 — Analysis

L3.1

Q. Ek page ko 4 origins chahiye. TCP handshake ≈ 1 RTT aur TLS ≈ 2 RTTs. HTTP/1.1 ke under browser sabse busy origin ke liye 6 connections kholta hai lekin har origin ko independently contact kiya jaata hai; per-origin cost lo kyunki ek origin ke connections kuch bhi fast share nahi karte. Setup RTTs compare karo: HTTP/1.1 (ek origin ke liye 6 cold connections) vs HTTP/2 (1 connection). 1 RTT = 40 ms diye hue, us ek origin ke liye dono setup times do.

Recall Solution

Per connection setup RTTs.

  • HTTP/1.1, ek origin ke liye 6 cold connections khule: handshakes time mein overlap kar sakte hain, lekin har connection phir bhi RTTs pay karta hai aur har ek tiny cold congestion window se shuru karta hai. Setup RTTs per connection RTT ms.
  • HTTP/2, 1 connection: RTT ms — same handshake latency, lekin chhah cold ones ki jagah sirf ek warmed congestion window.

Asli jeet handshake number mein nahi hai (dono RTTs setup); yeh hai ki HTTP/2 ise ek baar pay karta hai aur phir ek properly-grown congestion window reuse karta hai, jabki HTTP/1.1 ke chhah windows har baar cold start karte hain aur compete karte hain. Total handshake work: HTTP/1.1 RTT-connections of setup cost; HTTP/2 . Ratio kam setup cost.

L3.2

Q. Ek lost-packet scenario use karke explain karo ki HTTP/2 multiplexing head-of-line blocking kyon eliminate nahi karta, aur woh kis layer par rehta hai.

Recall Solution

Setup: teen streams (1, 3, 5) ek TCP connection par DATA frames interleave karte hain. Maan lo ek TCP segment jo stream 1 ka part carry karta hai network par lost ho jaata hai.

  • TCP guarantee karta hai ki application bytes in order receive kare. Toh TCP sab kuch buffer kar leta hai jo lost segment ke baad aaya — jisme streams 3 aur 5 ke perfectly-intact frames bhi hain — aur unhe tab tak upar dene se mana karta hai jab tak lost segment retransmit na ho jaaye (≈ 1 RTT baad).
  • HTTP/2 layer par, streams independent hain — wahan kuch block nahi karta. Lekin block ek layer neeche, TCP (transport) par hota hai.

Conclusion: HTTP/2 application-layer HOL blocking hataata hai lekin transport-layer HOL blocking nahi. HTTP/3 over QUIC har stream ko apni ordering deta hai, toh ek lost packet sirf apni stream ko stall karta hai — TCP dekho kyon in-order delivery wait force karta hai.

L3.3

Q. Ek 200-byte cookie 100 requests par bheji jaati hai. Us cookie ke liye total header bytes estimate karo (a) HTTP/1.1 ke under (har baar verbatim) aur (b) HTTP/2 HPACK ke under (ek baar literal-with-indexing, phir indexed). Indexed reference ko 1 byte lo.

Recall Solution

(a) HTTP/1.1: bytes. (b) HPACK: request 1 full literal bhejta hai ( bytes) aur dynamic table mein store karta hai; requests 2–100 har ek 1-byte index bhejti hai → bytes. Savings: bytes, ek shrink.


Level 4 — Synthesis

L4.1

Q. Is frame sequence ko design karo: client GET /index.html; server /style.css push karna chahta hai. Har frame ko uske Stream ID ke saath, order mein list karo, aur har ID justify karo.

Recall Solution
  1. HEADERS Stream 1 par — /index.html ke liye client ki request. Stream 1 odd hai → client-initiated. ✅
  2. PUSH_PROMISE Stream 1 par — requesting stream par announce kiya gaya, Stream 2 (even → server-initiated) pushed resource ke liye reserve karte hue.
  3. HEADERS Stream 2 par — /style.css ke liye response headers.
  4. DATA Stream 2 par — CSS bytes.
  5. HEADERS Stream 1 par — /index.html ke liye response headers.
  6. DATA Stream 1 par — HTML bytes.

Key point: promise client ki stream (1) par sawaar hoti hai, lekin pushed content ek nayi even stream (2) par rehta hai, toh kisi bhi odd client stream se kabhi collide nahi karta. Jab parser <link> style.css ka discover karta hai, woh already aa raha/cached hota hai → round trip bachaya.

L4.2

Q. Neeche diye header list ko total HPACK bytes mein compress karna hai. Assume karo ki teenon static/dynamic table mein dikhaye gaye indices ke saath hain, sab 7-bit prefix mein fit hote hain, aur har fully-indexed header 1 byte cost karta hai. Total do. :method GET (idx 2), :path / (idx 4), :scheme https (idx 7)

Recall Solution

Har index , toh har ek single fully-indexed byte hai: 1 || 7-bit index.

  • idx 2 → 1 byte
  • idx 4 → 1 byte
  • idx 7 → 1 byte

Total bytes teen poori header lines ke liye. (Compare: unhe text mein likhna dozens of bytes hota.)


Level 5 — Mastery

L5.1

Q. Ek malicious page CRIME-style attack try karti hai: woh ek header inject karti hai jiska value woh control karti hai aur hope karti hai ki compressed size secret cookie ke bytes reveal kare. Precisely explain karo ki HPACK ke kaun se design choices ise defeat karte hain, aur woh transport layer ka naam lo jo abhi bhi protection chahta hai.

Recall Solution

Do HPACK properties attack todti hain:

  1. Attacker+secret par koi adaptive entropy coding nahi. HPACK ki string compression ek static Huffman table use karti hai jo spec mein fixed hai, koi adaptive coder nahi jo attacker text secret text se match hone par shrink ho. Toh compressed length ab signal nahi karta "tumhara guess ek secret byte se mila."
  2. Indexing per-whole-header, table-based hai. Ek secret cookie ya toh ek table index hai (opaque, fixed 1 byte) ya ek literal — yeh gzip ki sliding window ki tarah attacker input ke saath byte-by-byte mix nahi hoti.

Ye dono milke woh length-vs-guess correlation hatate hain jo CRIME exploit karta tha. Woh layer jo abhi bhi apni protection chahti hai woh hai TLS (connection ki encryption/integrity); HPACK compression side protect karta hai, TLS confidentiality side protect karta hai. CRIME-and-BREACH-attacks dekho.

L5.2

Q. Prove karo ki prefix-integer round-trips: ko 5-bit prefix mein encode karo, phir byte sequence ko decode karo aur confirm karo ki recover hota hai.

Recall Solution

Encode (L2.3 se): prefix ; remainder → bytes 31, 154, 10. Decode: prefix all-ones hai () → accumulator se shuru karo, phir continuation bytes padho:

  • byte : high bit set (subtract ), add . Accumulator . Aur aayenge.
  • byte : high bit clear → add , phir ruko. Accumulator . ✅

recover hua — encoding lossless hai. Yahi varint idea hai: 7 data bits per byte, top bit = continuation flag.

L5.3

Q. 24-bit Length field diya hua hai, aur jaante hue ki frames default par bytes hote hain, kitne default-max frames chahiye ek 1 MiB (-byte) response body carry karne ke liye, aur kya ek single frame us size ka Length field se representable bhi hoga?

Recall Solution

Default frame payload bytes. Body bytes. Number of frames frames exactly. Ek frame mein representable hai? Length field bytes tak hold karta hai, aur , toh haan, ek single 1 MiB frame representable hai — lekin sirf tabhi jab peer ne SETTINGS_MAX_FRAME_SIZE raise kiya ho. By default aap frames of KiB bhejoge taaki koi single frame connection ko monopolise na kare.


Recall Self-test one-liners

Odd Stream IDs kiske hote hain? ::: Client ke (client-initiated streams). Even Stream IDs kiske hote hain? ::: Server ke (pushed streams). Default max frame payload bytes mein? ::: 16384 (). HPACK ke teen mechanisms? ::: Static table, dynamic table, static Huffman coding. HTTP/2 kaun sa HOL blocking abhi bhi suffer karta hai? ::: Transport-layer (TCP in-order delivery). Server push ka modern replacement? ::: 103 Early Hints + link rel=preload.