HTTP is the stateless request–response protocol of the web: a client sends a method, a URL and headers; the server answers with a status code, headers and a body. Methods, status codes, headers, cookies and versions are favourite exam material.
HTTP is like ordering at a counter on a strict printed form. You fill in what to do (the method — GET to fetch, POST to submit), which item (the URL) and extra notes (headers: your language, formats you accept). The clerk replies with a numbered stamp — 200 here you are, 404 no such item, 500 our fault — plus notes and the item itself. The clerk forgets you the moment you step away, so to be recognised next time you must show a token: a cookie.
Key points — the night-before list
Request = request line (method, target, version) + headers + blank line + optional body. Response = status line (version, code, reason) + headers + blank line + body.
Safe (read-only): GET, HEAD, OPTIONS, TRACE. Idempotent: those four plus PUT and DELETE. POST and PATCH are neither in general.
Status classes: 1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error — e.g. 200, 201, 204, 301, 302, 304, 400, 401, 403, 404, 500, 503.
HTTP is stateless; cookies add state (Set-Cookie → Cookie). Attributes: Expires/Max-Age, Domain, Path, Secure, HttpOnly, SameSite.
HTTP/1.0: a new TCP connection per object. HTTP/1.1: persistent connections by default, mandatory Host. HTTP/2: binary frames, multiplexing, HPACK. HTTP/3: QUIC over UDP.
GET puts data in the URL (cacheable, bookmarkable, length-limited); POST puts it in the body (not cached, any size, binary allowed). Neither is encrypted without HTTPS.
HTTPS = HTTP over TLS (successor of SSL) on port 443; plain HTTP uses port 80. A conditional GET (If-None-Match / If-Modified-Since) can return 304 Not Modified.
01HTTP in one picture
The HyperText Transfer Protocol (HTTP) is the application-layer protocol browsers and servers use to exchange web resources. It follows the client–server model: the client sends a request naming a resource by its URL, and the server returns a response. Classic HTTP runs over TCP on port 80; HTTPS wraps the same messages in TLS on port 443; HTTP/3 runs over QUIC on UDP.
Tim Berners-Lee created HTTP at CERN in 1989–91 together with HTML and the first browser. HTTP/0.9 (1991) had a single one-line GET and no headers. HTTP/1.0 (RFC 1945, 1996) added headers, status codes and POST. HTTP/1.1 (RFC 2068 in 1997, RFC 2616 in 1999, today RFC 9110 + RFC 9112 from 2022) is still the most widely understood version. HTTP/2 (RFC 7540 in 2015, now RFC 9113) and HTTP/3 (RFC 9114, 2022) keep the same meaning but change how bytes travel.
What happens when you open https://portal.kshb.example/
DNS lookup
The browser asks DNS for the IP address of portal.kshb.example (unless it is cached).
TCP handshake
SYN, SYN-ACK, ACK with port 443 of that address — one round trip.
TLS handshake
For HTTPS only: agree on keys and verify the server's certificate.
HTTP request
GET / HTTP/1.1 plus headers such as Host, User-Agent, Accept and any cookies.
HTTP response
HTTP/1.1 200 OK, headers, a blank line and the HTML.
Sub-resources
The browser parses the HTML and requests the CSS, JavaScript and images it references, usually over the same connection.
Render
The page is laid out and painted; scripts may make further (AJAX) requests.
PSC favourite
Order of events when a browser fetches a page: DNS query → TCP SYN → HTTP GET (asked in a 2023 PSC paper). The name must be resolved first, and a TCP connection must exist before any HTTP message can be sent.
02Message format with real examples
HTTP/1.x messages are plain text. Every line ends with CR LF, and an empty line separates the headers from the body. Here is the login of our housing-board portal, exactly as it travels (inside TLS):
TextRequest: request line, headers, blank line, body. The body is exactly 29 bytes long
Method SP request-target SP version — POST /login.php HTTP/1.1
Version SP status-code SP reason-phrase — HTTP/1.1 302 Found
Headers
Name: value lines describing the client, the body and preferences
Name: value lines describing the server, the body and caching
Blank line
Mandatory — marks the end of the headers
Mandatory
Body
Optional — form data, JSON, an uploaded file
Optional — HTML, JSON, an image (none for 204, 304 or HEAD)
Content-Length counts bytes of the body only: username=anil&password=s3cret is 8 + 1 + 4 + 1 + 8 + 1 + 6 = 29 characters. When the length is not known in advance, the server can instead send Transfer-Encoding: chunked and stream the body in pieces.
Send data for the resource to process; often creates a subordinate resource
Yes
Submit a form, log in, upload, place an order
PUT
Create or replace the resource at this URL with the enclosed representation
Yes
Save a whole document or record
DELETE
Remove the resource
Usually no
Delete a record
PATCH
Apply a partial modification (RFC 5789)
Yes
Change one field of a record
OPTIONS
Ask which methods and features the resource supports
No
CORS pre-flight; reply carries Allow
TRACE
Loop-back test: the server echoes the request it received
No
Diagnose proxies; usually disabled for security
CONNECT
Open a tunnel to another host through a proxy
No
HTTPS through a forward proxy
A method is safe if it is read-only — the client does not ask for any change on the server. A method is idempotent if sending the same request several times has the same effect on the server as sending it once. Every safe method is idempotent, but not the other way round.
Method
Safe
Idempotent
Cacheable
GET
Yes
Yes
Yes
HEAD
Yes
Yes
Yes
OPTIONS
Yes
Yes
No
TRACE
Yes
Yes
No
PUT
No
Yes
No
DELETE
No
Yes
No
POST
No
No
Only with explicit freshness information (rare)
PATCH
No
Not guaranteed
No
CONNECT
No
No
No
Properties as defined in RFC 9110 (and RFC 5789 for PATCH)
Example: DELETE /schemes/7 sent twice returns 204 the first time and 404 the second, but the server state after both is the same — scheme 7 is gone — so DELETE is idempotent. POST /applications sent twice creates two applications, which is why browsers warn before re-submitting a POST and why payment pages guard against double clicks.
PSC favourite
PUT creates or replaces the target resource with the enclosed representation and is idempotent (asked in 2026). TRACE performs a message loop-back test and returns the request as received (asked in 2024). HEAD is GET without the body.
04Status codes
Every response carries a three-digit status code; the first digit gives the class: 1xx informational, 2xx success, 3xx redirection, 4xx client error (the request was wrong), 5xx server error (the request was fine but the server failed). The reason phrase after the code is only for humans.
Code
Reason phrase
Meaning / when used
100
Continue
Go ahead and send the body (reply to Expect: 100-continue before a large upload)
101
Switching Protocols
Server agrees to change protocol, e.g. upgrade to WebSocket
200
OK
Success; the body holds the result
201
Created
A new resource was created (after POST or PUT); Location gives its URL
202
Accepted
Accepted for processing later (an asynchronous job)
204
No Content
Success with nothing to return — typical for DELETE or a save
206
Partial Content
A byte range was served (resumable downloads, video seeking)
301
Moved Permanently
Use the new URL in Location from now on; bookmarks and search engines update
302
Found
Temporary redirect; browsers follow it with GET
303
See Other
Fetch the result with GET at Location (the Post/Redirect/Get pattern)
304
Not Modified
Your cached copy is still valid (reply to a conditional GET); no body
307
Temporary Redirect
Like 302, but the method and body must stay the same
308
Permanent Redirect
Like 301, but the method is preserved
400
Bad Request
Malformed syntax or invalid request
401
Unauthorized
Authentication required or failed; the response carries WWW-Authenticate
403
Forbidden
Understood but refused; logging in again will not help
404
Not Found
Nothing exists at this URL
405
Method Not Allowed
Method not supported here; the Allow header lists the allowed ones
408
Request Timeout
The client took too long to send its request; the server closes the connection
409
Conflict
Clashes with the current state (two people editing one record)
413
Content Too Large
Body bigger than the server accepts (an oversized upload)
429
Too Many Requests
Rate limit exceeded; Retry-After says when to try again
500
Internal Server Error
Unhandled error in the server's code
501
Not Implemented
The server does not support this method or feature at all
502
Bad Gateway
A proxy or gateway received an invalid response from the upstream server
503
Service Unavailable
Overloaded or down for maintenance; may carry Retry-After
504
Gateway Timeout
A proxy or gateway got no timely response from the upstream server
401 Unauthorized
Really means unauthenticated: who are you?
Sent when credentials are missing or wrong
Comes with WWW-Authenticate naming the scheme
Logging in may fix it
403 Forbidden
You are known, but not allowed
Sent when permissions are insufficient
No challenge header
Logging in again will not fix it
Memory hook
2xx here you go · 3xx go elsewhere · 4xx you messed up · 5xx we messed up. And 502/504 always involve a gateway or proxy talking to an upstream server.
05Headers that matter
Header
Sent by
Purpose and example
Host
Request
Target host (and port); mandatory in HTTP/1.1 — Host: portal.kshb.example
User-Agent
Request
Client software — Mozilla/5.0 (…); used for statistics and compatibility
Accept, Accept-Language, Accept-Encoding
Request
Content negotiation: types (text/html), languages (ml, en;q=0.8), compression (gzip, br)
Content-Type
Both
MIME type of the body — application/json; charset=UTF-8
Content-Length
Both
Size of the body in bytes
Cookie
Request
Cookies the browser returns — Cookie: lang=ml; PHPSESSID=9f2c…
Version tag ("v42-9f1c") or modification time of the representation
If-None-Match / If-Modified-Since
Request
Conditional GET: send the body only if it changed, else reply 304
Location
Response
Target URL for 3xx redirects and for 201 Created
Authorization
Request
Credentials — Basic … or Bearer <token>
WWW-Authenticate
Response
Sent with 401: which authentication scheme to use
Referer
Request
Address of the page that linked here
Connection
Both
keep-alive or close (HTTP/1.x only)
Transfer-Encoding
Response
chunked — body sent in pieces when its length is not known in advance
With HTTP Basic authentication the client sends Authorization: Basic YW5pbDpzM2NyZXQ=, which is simply Base64 of anil:s3cret. Base64 is an encoding, not encryption — anyone who sees the header can decode it — so Basic authentication is acceptable only over HTTPS. Token schemes send Authorization: Bearer <token> instead.
Watch out
Referer is spelled with a single r in the middle — a typo frozen into the standard since the 1990s. (The newer Referrer-Policy header is spelled correctly.)
06Statelessness and cookies
HTTP is stateless: each request is handled on its own, and the server keeps no memory of earlier requests from the same client. That makes servers simple and easy to scale — any server can answer any request — but a shopping cart or a login needs memory across requests. Cookies supply it.
A cookie is a small name=value pair that the server asks the browser to store with a Set-Cookie response header. On every later request to a matching URL the browser sends it back in a Cookie header. Cookies were invented at Netscape in 1994 (by Lou Montulli) and are standardised in RFC 6265 (2011). Browsers must support at least 4096 bytes per cookie and 50 cookies per domain.
TextA session cookie; a 30-day cookie; a cookie shared with all of kshb.example; and how to delete one
Relative lifetime; wins over Expires if both are given; 0 deletes the cookie
Domain=kshb.example
Send to this domain and all its subdomains; if omitted the cookie is host-only (exact host)
Path=/staff
Send only for URLs whose path starts at /staff
Secure
Send only over HTTPS
HttpOnly
Hide from JavaScript (document.cookie) — limits theft by cross-site scripting
SameSite=Strict
Never send on requests that come from another site
SameSite=Lax
Send on top-level GET navigations from other sites but not on cross-site POSTs or embedded requests — the default in modern browsers
SameSite=None
Always send, including cross-site; must be combined with Secure
Session cookie
No Expires and no Max-Age
Kept in memory; deleted when the browser closes
Typical for session ids
Persistent cookie
Has Expires or Max-Age
Saved on disk until it expires or is deleted
Typical for 'remember me', language and theme preferences
Tip
Try the HTTP, forms & sessions tool on this page: submit the login form, watch Set-Cookie: PHPSESSID=… come back, then see the browser attach Cookie: to every later request.
07Connections and versions: 1.0, 1.1, 2 and 3
With non-persistent connections (the HTTP/1.0 default) the client opens a new TCP connection for every object and closes it after one response. With persistent connections (the HTTP/1.1 default, Connection: keep-alive) many requests reuse one connection, saving a TCP handshake — one round-trip time (RTT) — per object. HTTP/1.1 also allows pipelining (sending several requests without waiting), although browsers rarely enabled it.
RTT = round-trip time; a base HTML page referencing n objects; transmission time ignored
Non-persistent, serial : (n + 1) × 2 RTT
Non-persistent, parallel : 2 RTT (base) + 2 RTT (all n objects at once)
Persistent, no pipelining : 2 RTT (base) + n × 1 RTT
Persistent, with pipelining : 2 RTT (base) + 1 RTT (all n requests back to back)
Response-time models in the style of Kurose & Ross — each new TCP connection costs one extra RTT
Version
Year and spec
Key features
HTTP/0.9
1991
One-line GET only; no headers or status codes; HTML only
HTTP/1.0
1996, RFC 1945
Headers, status codes, Content-Type, POST and HEAD; a new TCP connection per request
HTTP/1.1
1997/1999, now RFC 9112
Persistent connections by default, pipelining, mandatory Host, chunked transfer, PUT/DELETE/OPTIONS/TRACE/CONNECT, Cache-Control and ETag, range requests
HTTP/2
2015, RFC 7540 → RFC 9113
Binary framing; many streams multiplexed over one TCP connection; HPACK header compression; server push (since abandoned by browsers); stream priorities
HTTP/3
2022, RFC 9114
Runs over QUIC on UDP port 443; TLS 1.3 built in; faster connection set-up; streams independent at the transport level; connection migration; QPACK compression
Why HTTP/3? HTTP/2 solved application-level head-of-line blocking — one slow response no longer holds up the others on the connection — but all streams still share one TCP byte stream, so a single lost packet stalls every stream until it is retransmitted. QUIC delivers each stream independently, so a loss delays only the stream it belongs to.
HTTPS is HTTP sent through a TLS tunnel (TLS replaced the older SSL). It encrypts the request line, headers — including cookies — and body; it protects integrity; and the server's X.509 certificate, signed by a certificate authority, proves the site's identity. The server's IP address, and usually its host name, remain visible to the network.
08GET vs POST, and caching basics
Aspect
GET
POST
Where the data goes
In the URL query string (?district=Kollam)
In the request body
Visible in
Address bar, history, bookmarks, server logs, Referer
Not in the URL (but plain text on the wire without HTTPS)
Size
Limited by practical URL length (a few thousand characters)
No practical limit (only server settings such as PHP's post_max_size)
Data types
Text only, URL-encoded
Text or binary (multipart/form-data for files)
Caching and bookmarks
Cacheable; can be bookmarked and shared
Not cached by default; cannot be bookmarked
Back / refresh
Harmless re-fetch
Browser warns about resubmitting
Semantics
Safe and idempotent
Neither safe nor idempotent
Use for
Search, filters, reading data
Login, forms that change data, uploads, payments
Caching avoids re-downloading unchanged resources. The server states freshness with Cache-Control: max-age=86400 (fresh for a day; the older HTTP/1.0 header was Expires), and attaches a validator — an ETag or a Last-Modified date. Once the copy is stale, the browser makes a conditional GET with If-None-Match or If-Modified-Since; if nothing changed the server answers 304 Not Modified with no body.
TextRevalidation: a few hundred bytes instead of the whole stylesheet
GET /css/site.css HTTP/1.1
Host: portal.kshb.example
If-None-Match: "v42-9f1c"
HTTP/1.1 304 Not Modified
ETag: "v42-9f1c"
Cache-Control: max-age=86400
public — any cache (browser, proxy, CDN) may store it; private — only the user's browser.
no-cache — may be stored, but must be revalidated with the server before every use.
no-store — must not be stored at all (banking pages, personal data).
must-revalidate — once stale, never serve it without checking with the server.
Watch out
no-cache does not mean 'do not cache' — it means 'store, but check before reuse'. To forbid storage use no-store.
Step through · First visit, then a revisit with cookies and caching
step 1 / 9
Step 1: Query: portal.kshb.example?
Before any HTTP can happen the name must be turned into an IP address.
Worked examples
Try the problem first, then reveal the working one step at a time.
EX 1Persistent vs non-persistent connections (classic numerical)
A page consists of a base HTML file and 8 small images on the same server. RTT = 40 ms and transmission times are negligible. Find the total time to fetch everything with (a) non-persistent serial connections, (b) non-persistent parallel connections (all 8 images at once), (c) persistent connections without pipelining, (d) persistent connections with pipelining.
EX 2Reading a raw request
A monitoring tool captures a request with these four lines: GET /api/schemes?district=Kollam HTTP/1.1, Host: api.kshb.example, Accept: application/json and Authorization: Basic a3NoYjpob3VzaW5n. Explain every part, recover the credentials, and give the status codes for wrong credentials, a valid user without permission, and success.
EX 3Designing a REST API for housing schemes
Choose the method and the success status code for each operation on the resource /schemes: list all; read one; add a new scheme; replace scheme 7 completely; change only the unit count of scheme 7; delete scheme 7. Also give the status for reading the non-existent scheme 99 and for calling DELETE on a read-only endpoint.
EX 4Which cookies does the browser send?
https://portal.kshb.example sets three cookies: A lang=ml; Path=/ (no Domain), B sid=81fa; Path=/staff; Secure; HttpOnly, C theme=dark; Domain=kshb.example; Path=/. Which cookies go with requests to (1) https://portal.kshb.example/staff/home (2) http://portal.kshb.example/staff/home (3) https://www.kshb.example/ (4) https://portal.kshb.example/staffroom?
Practice session
Work each problem on paper first, then check. Marking one solved earns 10 XP.0/5 solved
Q1
Classify GET, HEAD, POST, PUT, DELETE, PATCH, OPTIONS and TRACE as safe and/or idempotent. Which of them may a search-engine crawler send freely without risking changes on a site?
Q2
Give the most appropriate status code: (a) a new application record was created; (b) a logged-in clerk opens the admin-only page; (c) a visitor who is not logged in calls a protected API; (d) the browser's cached copy is still valid; (e) the site is down for planned maintenance; (f) the whole site has moved to a new domain for good; (g) the client opened a connection but never finished sending its request; (h) Nginx could not get any reply from the Tomcat behind it in time.
Q3
A 'Remember me for 30 days' cookie must be set. Write the Set-Cookie header using Max-Age, make it HTTPS-only and invisible to JavaScript, and then write the header that deletes it.
Q4
A base HTML file references 5 images. RTT = 100 ms and each object (HTML or image) takes 10 ms to transmit. Compute the total time for (a) non-persistent serial HTTP, (b) persistent HTTP without pipelining, (c) persistent HTTP with pipelining.
Q5
A GET form has fields name = "Anil Kumar" and district = "Kollam & Kochi". Write the query string the browser builds. If the same form used POST, what would Content-Type and Content-Length be?
Exam traps
401 Unauthorized actually means unauthenticated (log in first); 403 Forbidden means you are known but not allowed.
Idempotent ≠ safe: DELETE changes state, yet repeating it changes nothing further; GET is both safe and idempotent.
POST data is not secure merely because it is not in the URL — without HTTPS it travels in plain text.
Cache-Control: no-cache allows storing but forces revalidation; no-store forbids storing.
HTTP/1.1 permits pipelining, but browsers never enabled it widely; real concurrency came from several parallel connections and then HTTP/2 multiplexing.
Some older books list only GET and HEAD as safe; RFC 9110 lists GET, HEAD, OPTIONS and TRACE. Use the RFC list unless the question clearly follows an older text.
Quiz — KPSC style
12 questions. 70 % passes the topic quiz (+30 XP, +20 more for 100 %). Exam scoring: +1 correct, −⅓ wrong.
HTTP: methods, status codes, headers & cookies · Question 1 of 12✓ 0 · ✗ 0
In an HTTP response, status code 404 indicates:
Past-paper questions on this topic
Modelled on real KPSC questions (reworded) with the same concept and answer; each links to its original paper.
Past papers · Question 1 of 12✓ 0 · ✗ 0
Modelled on QP 050/2026 · Deputy Manager (IT) / Assistant Programmer / Computer Programmer etc (20 May 2026), Q.72 (reworded)original paper (PDF)
Which HTTP method asks the server to create or replace the target resource with the representation in the request body, and is idempotent?