Computer Networking › Section B · The application layer › Topic B.2

The web and HTTP

Opening a single web page can trigger dozens of requests. The Hypertext Transfer Protocol (HTTP) defines those requests and replies, and its three versions in use today, HTTP/1.1, HTTP/2 and HTTP/3, show how a simple protocol has been reshaped for speed.

Pages, objects and URLs

A web page is a base HTML file plus the objects it references, such as images, style sheets and scripts. Each object has a URL: in https://www.example.com/shop/cart.html, the host name is www.example.com and the path is /shop/cart.html. A browser, the client, asks a web server for objects with HTTP, and the server sends them back. Classic HTTP runs over TCP, on port 80 for plain HTTP and 443 for HTTPS, which is HTTP protected by TLS. HTTP is stateless: the server keeps no memory of earlier requests, which keeps servers simple.

Non-persistent and persistent connections

The round-trip time (RTT) is the time for a small packet to reach the server and a reply to return. Opening a TCP connection costs one RTT for the handshake, and each request and response costs at least one more. With non-persistent connections, used by early HTTP/1.0, every object needed a new connection, so each took at least 2 RTT plus its transmission time. HTTP/1.1 made connections persistent by default: the server leaves the connection open, so later objects cost only one RTT each. Browsers also open several connections in parallel to the same server to speed things up.

The request message

An HTTP/1.1 request is plain text. The request line holds a method, a path and a version, as in GET /shop/cart.html HTTP/1.1. Header lines follow, such as Host: www.example.com, which is required because one server may host many sites; User-Agent, naming the browser; and Accept-Language: en. A blank line ends the headers, and a body may follow. GET retrieves an object, HEAD fetches only its headers, POST submits data such as a form, PUT replaces a resource, PATCH modifies part of it and DELETE removes it.

The response message

A response starts with a status line such as HTTP/1.1 200 OK, then headers such as Date, Content-Type: text/html, Content-Length and Last-Modified, a blank line and the body. Status codes fall into five classes: 1xx informational, 2xx success, 3xx redirection, 4xx client error and 5xx server error. Common ones are 200 OK, 301 Moved Permanently, whose Location header gives the new URL, 304 Not Modified, 400 Bad Request, 404 Not Found, 500 Internal Server Error and 503 Service Unavailable. A 404 means the request reached the server but named something that does not exist.

Worked example: timing a page load

A page has one HTML file and 6 images on the same server, with an RTT of 40 ms. Ignore transmission times and use one connection at a time. 1. Non-persistent: each of the 7 objects needs a handshake RTT and a request RTT, so \(7 \times 2 \times 40 = 560\) ms. 2. Persistent, one request at a time: one handshake, then one RTT per object, so \(40 + 7 \times 40 = 320\) ms. 3. Persistent, with all 6 image requests sent together once the HTML arrives, as HTTP/2 allows: \(40 + 40 + 40 = 120\) ms. Check: the savings come entirely from waiting fewer round trips, which is why latency, not bandwidth, often limits page loads. Adding TLS 1.3 costs one more RTT at the start.

Cookies: state on a stateless protocol

Shops and logins need to recognise returning users, so HTTP uses cookies. On a first visit the server's response includes a header such as Set-Cookie: session=7f3a9c. The browser stores it and sends Cookie: session=7f3a9c with every later request to that site, and the server uses the value as a key into its own database of carts and login state. Cookies also raise privacy concerns: third-party cookies, set by advertising domains embedded in many sites, let one company follow a user across the web, so browsers increasingly restrict them.

Web caching and conditional requests

A web cache keeps copies of recently fetched objects so that repeated requests are answered nearby. Browsers have their own caches; organisations and ISPs can run proxy caches; content distribution networks are caches spread around the world. The server's Cache-Control header, such as Cache-Control: max-age=3600, says how long a copy stays fresh. After that, the cache revalidates with a conditional GET: it sends If-Modified-Since with the stored date, or If-None-Match with the stored ETag, a version tag. If nothing has changed, the server replies 304 Not Modified with no body, and the cache serves its copy.

Worked example: what a cache saves

A college installs a proxy cache. A hit is served in about 10 ms; a miss must go to the origin server and takes about 150 ms. Measurements show 60% of requests are hits. 1. Average delay: \(0.6 \times 10 + 0.4 \times 150 = 6 + 60 = 66\) ms, compared with 150 ms without the cache. 2. Only misses cross the college's access link, so web traffic on that link falls to 40% of its old level. 3. If web traffic had kept the link 90% busy, it now uses about \(0.4 \times 90\% = 36\%\). Check: misses still dominate the average, so a higher hit rate pays off most, and a cache can cost less than a faster link.

HTTP/2: many streams, one connection

HTTP/2, first published in 2015, keeps HTTP's methods, headers and status codes but changes how they travel. Messages are split into binary frames, and each request-response pair becomes a stream. Frames from many streams are interleaved on one TCP connection, so a large video file no longer blocks the small style sheet requested after it. Headers are compressed, since the same ones repeat in every request, and clients can signal priorities. The standard also defined server push, sending objects before they are requested, but it saw little use, and Chrome and Firefox have since removed support for it.

HTTP/3: HTTP over QUIC

HTTP/2 still has one weakness: TCP delivers bytes strictly in order, so a single lost segment stalls every stream on the connection until it is retransmitted. This is head-of-line blocking at the transport level. HTTP/3, standardised in 2022 (RFC 9114), runs over QUIC, which carries each stream independently on top of UDP, so a loss delays only its own stream. QUIC builds in TLS 1.3, combining the transport and encryption handshakes into a single round trip, and lets a connection survive a change of IP address, such as a phone moving from Wi-Fi to mobile data. All three versions are in everyday use and share the same HTTP semantics.

Common mistakes to avoid

First, thinking HTTP remembers clients; it is stateless, and cookies supply the memory. Second, counting only one RTT per object with non-persistent connections, forgetting the handshake. Third, treating 304 as an error; it is a redirection-class reply telling the client to use its cached copy. Fourth, believing HTTP/2 removed all head-of-line blocking; on TCP, one loss still stalls every stream, which HTTP/3 fixes. Fifth, thinking HTTP/3 is a new set of methods; only the transport changed. Sixth, confusing a 404, where the server answered, with a failure to reach the server at all.

Key takeaways

A web page is a base HTML file plus referenced objects, each named by a URL. HTTP is a stateless request-response protocol: requests carry a method, path, version and headers such as Host; responses carry a status code and headers. Non-persistent connections cost about 2 RTT per object, persistent ones about 1 RTT after the handshake. Cookies, set with Set-Cookie, give sites state. Caches and conditional GETs with 304 replies cut delay and traffic. HTTP/2 multiplexes framed streams over one TCP connection; HTTP/3 runs those streams over QUIC to avoid transport-level head-of-line blocking.

Flashcards

Flashcard

Web page

A base HTML file plus the objects it references

Images, scripts, style sheets.

Test your understanding

Question 1 of 5

A page has an HTML file and 4 images on one server, with RTT 25 ms. Using non-persistent connections one at a time and ignoring transmission time, how long does it take?

Question 2 of 5

A cache sends a conditional GET and receives 304 Not Modified. What happens next?

Question 3 of 5

Why can HTTP/3 avoid the head-of-line blocking that still affects HTTP/2?

Question 4 of 5

Which header does a server use to start tracking a returning visitor?

Question 5 of 5

A cache has a 70% hit rate. Hits take 10 ms and misses 120 ms. What is the average delay?

← Previous topicNext topic →