Foundations — HTTP - 1.1 — methods, status codes, headers, persistent connections
4.3.24 · D1· Coding › Computer Networks › HTTP - 1.1 — methods, status codes, headers, persistent conn
Is page pe assume kiya gaya hai ki tumhe kuch nahi pata. parent topic padhne se pehle, tumhe kuch ideas pakke kar lene hain. Hum har ek ko ek picture se build karte hain, batate hain ki topic ko uski zaroorat kyun hai, aur tabhi uski notation use karte hain.
0. "Protocol" hota kya hai?
Picture: do log phone pe jo pehle se agree kar chuke hain ki "main hello bolunga, phir tum hello bologe, phir main apna sawaal puhunga." Koi doosre pe bolta nahi; dono ko pata hai ki doosra kab khatam ho gaya.
Topic ko kyun chahiye: HTTP ek protocol hai. Parent note ki har rule ("start line pehle", "blank line headers khatam karti hai") us agreement ka bas ek clause hai.
1. Client aur Server — do roles

Figure 1 walkthrough: left pe cyan box client hai; right pe amber box server hai. Top wala white arrow (client → server) request hai; bottom wala white arrow (server → client) response hai. Padhne ki direction kabhi nahi palti: HTTP/1.1 mein client hamesha pehle bolta hai.
Topic ko kyun chahiye: har HTTP message ya to request (client → server) hai ya response (server → client). Parent note mein "request–response" phrase in donoRoles pe based hai.
2. TCP — woh reliable pipe jis par HTTP chalta hai
Yahan ek sabse important background fact hai: HTTP khud bytes ko internet par nahi bhejta. Woh apna text ek lower layer ko deta hai jise TCP kehte hain.
Picture: client aur server ko connect karne wali ek garden hose. HTTP text paani hai. TCP guarantee karta hai ki paani order mein pahunche.
2a. 3-way handshake — pipe kholne mein time kyun lagta hai
Koi bhi HTTP text flow karne se pehle, TCP ko pipe kholni padti hai. Woh yeh teen chhote messages aage-peeche bhej kar karta hai.

Figure 2 walkthrough: cyan vertical line client ki timeline hai, amber line server ki hai; time neeche ki taraf chalta hai. Teen white arrows handshake messages hain (SYN, phir SYN-ACK, phir ACK). Left pe amber double-headed arrow mark karta hai ki ek poora 1 RTT burn ho chuka hai pehle cyan note "only NOW can HTTP text flow" se — koi web data tab tak move nahi hota jab tak pipe khul na jaye.
Handshake 1 RTT kharch karta hai HTTP ka ek bhi byte bhejne se pehle. Yahi ek fact hai persistent connections ke exist karne ki poori wajah: har image ke liye nayi pipe kholna har baar ek RTT waste karta hai. Full mechanics ke liye TCP three-way handshake dekho.
3. Bytes, characters, aur CRLF — message ka fabric
HTTP ek text protocol hai. Parent note padhne ke liye tumhe teen chhoti ideas se comfortable hona chahiye.
Picture: ek purana typewriter. CR = carriage ko left margin par wapas slide karo; LF = paper ko ek line upar roll karo. Do mechanical actions = ek nayi line. HTTP ne woh pairing inherit ki.
4. URL aur path — tum kya maang rahe ho
Picture: ek envelope par address. Domain building hai; path uske andar room number hai.
Topic ko kyun chahiye: request start line METHOD /path HTTP/1.1 hai. Aur kyunki domain Host: mein split ho jata hai, ek building (ek server IP) kai companies ko hold kar sakti hai — yeh Virtual hosting hai, aur isliye Host: 1.1 mein mandatory ban gaya.
5. Header — ek labelled fact, Name: Value
Picture: ek shipping form ke fields — "Weight: 2kg", "Contents: books." Har ek name colon value hai; parser unhe ek line at a time tab tak padhta hai jab tak blank line na mile.
Topic ko kyun chahiye: parent note ki har capability (caching via ETag, sessions via Cookie, framing via Content-Length) bas ek header hai. Name: Value shape master karo aur header list scary nahi lagegi.
6. Method — request ka action verb
Picture: ek counter par form jisme checkbox hai — READ / ADD / REPLACE / REMOVE. Method woh box hai jo tum tick karte ho; URL woh record hai jis pe tick karte ho.
Topic ko kyun chahiye: request start line literally METHOD /path HTTP/1.1 hai. Parent note ki poori "methods" table bas yahi verb hai, aur agli section (safe/idempotent) un verbs ki properties describe karti hai.
7. Idempotent aur Safe — ek method ki properties
Yeh do adjectives methods (GET, POST…) ko describe karte hain. Log confuse ho jaate hain kyunki yeh similar lagte hain.
Picture:
- Safe = shelf se ek kitaab padhna. 100 baar padho; shelf unchanged. (GET.)
- Idempotent = ek light switch OFF set karna. Ek ya das baar OFF karo → phir bhi OFF. (PUT, DELETE.)
- Na safe na idempotent = jar mein ek coin daalna. Har repeat ek aur coin add karta hai — state change hoti rehti hai. (POST.)
8. Status code — ek 3-digit verdict
Picture: paanch rangon wala ek traffic-light system — pehle digit pe nazar dalo aur details padhne se pehle instantly mood pata chal jata hai.
Topic ko kyun chahiye: yeh response ka aadha hissa hai. "4 = client, 5 = server" jaankar tum akele code se hi zyaadatar HTTP problems debug kar sakte ho.
9. Sab kuch ek saath — ek poora HTTP message
Ab har ingredient (method, path, version, headers, blank line, body, status code) ka ek meaning hai. Yahan ek complete request aur ek complete response hai, line by line drawn.

Figure 3 walkthrough: upar se neeche padho.
- Cyan pehli line start line hai: request pe yeh
GET /index.html HTTP/1.1hai (method, path, version); response pe yehHTTP/1.1 200 OKhai (version, status code, reason phrase). - White boxes headers hain, har ek
Name: Valueshape mein. - Amber box blank line
\r\n\r\nhai — woh hard boundary jo kehti hai "headers khatam, body shuru ho sakti hai." - Cyan bottom box body hai (yahan
Hello, world!, 13 bytes — response keContent-Length: 13se match karta hua).
Yahi exact skeleton hai jo parent note assume karta hai. Tumhe ab usse shape dekhne ki zaroorat nahi — woh upar hai, fully labelled.
Prerequisite map
Neeche ki picture dikhati hai ki har foundation kaise feed karta hai agle mein, HTTP/1.1 topic tak pahunchte hue. Ek arrow "A → B" padho as "B samajhne se pehle A chahiye."
Agar koi bhi box fuzzy hai, toh parent note memorization jaisa lagega, understanding jaisa nahi.
Equipment checklist
Right side cover karo aur khud test karo — har ek ka jawab ek saanth mein dena chahiye.
Protocol kya hai, ek line mein?
HTTP mein request kaun bhejta hai aur response kaun bhejta hai?
TCP HTTP ko kya deta hai, aur kya nahi deta?
TCP connection kholne mein time kyun lagta hai?
Persistent connection kya hai?
RTT kya hai?
CRLF kaunse do bytes hain, aur blank line kya signal karti hai?
\r (13) aur \n (10); ek blank line (\r\n\r\n) signal karti hai "headers khatam, body shuru ho sakti hai."Har header ki kya shape hoti hai?
Name: Value, ek per line.HTTP method kya hai, aur teen name bolo?
Domain kahan jaata hai, aur path kahan jaata hai, ek request mein?
Host: header; path → start line mein request-target.