05 – HTTP and the Web
Course: ICT Basic course · Level: introductory Book: Kurose & Ross, 9th ed., chapter 2.2 (the Web and HTTP) and 2.6 (video streaming and CDNs)
Learning goals
After this article you can:
- explain how a web page is fetched with HTTP requests and responses;
- read and write simple HTTP messages (methods, status codes, headers);
- explain persistent connections, cookies and web caching;
- explain the differences between HTTP/1.1, HTTP/2 and HTTP/3 (QUIC);
- use
curl, browser developer tools and Wireshark to look at HTTP traffic.
1. The Web in a nutshell
- A web page consists of a base HTML file plus objects: images, CSS, JavaScript, fonts, video...
- Every object has a URL:
1 2 3 | |
- HTTP (HyperText Transfer Protocol) is the application-layer protocol of the Web. It follows the client-server model: the browser sends requests, the web server sends responses.
- HTTP is stateless: the server doesn't remember earlier requests. Extra mechanisms such as cookies and tokens are needed to remember a user.
A modern web page often needs 50–100+ requests to many different servers (CDNs, analytics, advertising, fonts).
2. HTTP messages
2.1 Request
1 2 3 4 5 6 7 8 | |
| Method | Meaning |
|---|---|
| GET | get a resource |
| POST | send data to the server (form, login, file upload) |
| PUT / PATCH | replace / partially change a resource (REST APIs) |
| DELETE | delete a resource |
| HEAD | like GET, but only headers (no body) |
| OPTIONS | which methods are allowed (used in CORS) |
2.2 Response
1 2 3 4 5 6 7 8 9 | |
| Status code | Meaning | Examples |
|---|---|---|
| 1xx | informational | 101 Switching Protocols (WebSocket) |
| 2xx | success | 200 OK, 201 Created, 204 No Content |
| 3xx | redirection | 301 Moved Permanently, 302 Found, 304 Not Modified |
| 4xx | client error | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests |
| 5xx | server error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable |
3. Connections: non-persistent vs. persistent
Before HTTP data can be sent over TCP, a TCP connection must be set up (3-way handshake = 1 RTT), and for HTTPS also a TLS handshake (1 RTT with TLS 1.3).
| Type | How | Response time per object |
|---|---|---|
| Non-persistent (HTTP/1.0) | a new TCP connection for every object | ≈ 2 RTT + transmission time per object |
| Persistent (HTTP/1.1 default) | keep the connection open for more objects | ≈ 1 RTT per object after the first |
RTT = round-trip time: the time for a small packet to travel from client to server and back.
4. Remembering users: cookies
Because HTTP is stateless, websites use cookies:
1 2 3 4 5 | |
Cookies are used for login sessions, shopping carts and preferences, and also for tracking users across websites (third-party cookies). Under the GDPR/AVG and the Dutch Telecommunicatiewet, websites need consent for tracking cookies. Browsers increasingly block third-party cookies (Safari and Firefox by default).
Modern APIs often use tokens instead (e.g. a JWT in an Authorization: Bearer ... header).
5. Web caching and CDNs
- Browser cache: the browser stores objects locally. With a conditional GET (
If-Modified-SinceorIf-None-Matchwith an ETag) it asks: "has this changed?" If not, the server answers 304 Not Modified without a body, which saves bandwidth. - Proxy cache: a server in the company/ISP network that stores popular objects. Less common today because almost all traffic is encrypted (HTTPS), so a normal proxy can't see or cache it.
- CDN (Content Delivery Network): the modern form of caching. Content providers place copies of their content on servers close to users (Akamai, Cloudflare, Fastly, Netflix Open Connect inside ISP networks). This means lower delay, less load on the origin server and better protection against DDoS.
Headers that control caching: Cache-Control: max-age=..., no-store, private, ETag, Expires.
6. HTTP versions: from 1.0 to 3
| Version | Year | Transport | Key features |
|---|---|---|---|
| HTTP/1.0 | 1996 | TCP | one request per connection (obsolete) |
| HTTP/1.1 | 1997 (current spec: RFC 9112, 2022) | TCP | persistent connections, Host header (many websites on one IP), text-based. Still widely used, e.g. for APIs and simple servers |
| HTTP/2 | 2015 (RFC 9113) | TCP + TLS | binary, multiplexing of many requests over one connection, header compression (HPACK). Problem: head-of-line blocking in TCP (one lost packet blocks all streams) |
| HTTP/3 | 2022 (RFC 9114) | QUIC over UDP | independent streams (no HOL blocking across streams), built-in TLS 1.3, faster setup (1-RTT, 0-RTT resume), connection migration (Wi-Fi → 5G without reconnecting) |
Today the major browsers, CDNs and big platforms (Google, YouTube, Meta, Cloudflare) all support HTTP/3. A site usually announces HTTP/3 support with the response header Alt-Svc: h3=":443" or a DNS HTTPS record.
The meaning of HTTP (methods, status codes, headers) is the same in all versions (RFC 9110, HTTP Semantics). Only the way the bytes travel over the network differs.
7. Try it yourself
Tip: in older courses
telnet <server> 80was used for this. Telnet still works for plain HTTP but not for HTTPS, and it is often not installed by default any more. Usecurlorncinstead.
- Manual HTTP request with netcat (plain HTTP, on your own VM or a test site):
1printf 'GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n' | nc example.com 80 - With curl:
Which status code do you get from
1 2 3 4
curl -v http://example.com/ # -v shows request and response headers curl -I https://www.hva.nl # only headers (HEAD) curl -v --http2 https://www.google.com -o /dev/null curl -v --http3 https://www.google.com -o /dev/null # needs a curl with HTTP/3 supporthttp://www.hva.nl? Why? (Hint: redirect to HTTPS.) - Browser developer tools (F12 → Network tab): load a news site. How many requests? How many different domains? Which protocol column shows
h2orh3? - Wireshark: capture traffic while visiting an HTTP site (e.g.
http://gaia.cs.umass.edu/wireshark-labs/HTTP-wireshark-file1.html). Use the display filterhttp. Then do the same with an HTTPS site and filter ontlsorquic. What can you still see? - Test whether a site supports HTTP/3: https://http3check.net/
Check your understanding
- What are the parts of a URL?
- What is the difference between a GET and a POST request?
- What do status codes 301, 304, 403 and 503 mean?
- Why are persistent connections faster?
- Why are cookies needed?
- Name two improvements of HTTP/3 over HTTP/2.
References
Book
- Kurose & Ross, 9th ed., chapter 2.2 (Web and HTTP), 2.6 (video streaming and CDNs)
- Kurose & Ross Wireshark exercises (HTTP) – https://gaia.cs.umass.edu/kurose_ross/wireshark.php
Videos
- Code.org – The Internet: HTTP & HTML https://www.youtube.com/watch?v=kBXQZMmiA4s
- CrashCourse CS #30 – The World Wide Web https://www.youtube.com/watch?v=guvsH5OFizE
- ByteByteGo – HTTP/1 to HTTP/2 to HTTP/3 https://www.youtube.com/watch?v=a-sBfyiXysI
Articles and standards
- MDN Web Docs – HTTP – https://developer.mozilla.org/en-US/docs/Web/HTTP
- RFC 9110 – HTTP Semantics – https://www.rfc-editor.org/rfc/rfc9110
- RFC 9114 – HTTP/3 – https://www.rfc-editor.org/rfc/rfc9114
- Daniel Stenberg (curl author) – HTTP/3 explained (free book) – https://http3-explained.haxx.se/
- The Illustrated QUIC Connection (every byte explained) – https://quic.xargs.org/
Cyber Security
Why is this important for cyber security?
- Plain HTTP can be read and changed by anyone on the path. Passwords, cookies and form data travel in clear text. On public Wi-Fi an attacker can read them or inject content (malware, ads). You can see this yourself with Wireshark (article 15).
- Stolen session cookies = stolen account. If an attacker gets your session cookie (via an unencrypted connection, XSS, or malware that steals browser data, so-called infostealers), they can log in as you, sometimes even bypassing multi-factor authentication.
- The web is the biggest attack surface of most organisations. Injection, broken access control, misconfiguration and vulnerable components are in the OWASP Top 10.
- Cookies and tracking are privacy issues with legal consequences (GDPR/AVG fines).
- CDNs and reverse proxies help against DDoS, but they also see your traffic decrypted: you have to trust them.
What can you do to make it safe?
- HTTPS everywhere: use TLS for every site, also "simple" ones. Free certificates from Let's Encrypt (see article 17).
- HSTS: send
Strict-Transport-Security: max-age=31536000; includeSubDomainsso browsers never use HTTP for your site again. - Secure cookies: set
Secure(only over HTTPS),HttpOnly(not readable by JavaScript, protects against XSS) andSameSite=Lax/Strict(protects against CSRF). - Security headers:
Content-Security-Policy,X-Content-Type-Options: nosniff,Referrer-Policy,Permissions-Policy. Check your site with the Mozilla HTTP Observatory. - Validate input and encode output in web applications (OWASP).
- Hide unnecessary information: don't reveal exact server versions in headers (
Server: Apache/2.4.29) or detailed error messages. - As a user: check for HTTPS, be careful on public Wi-Fi, keep your browser updated, and use a password manager plus MFA.
Extra references
- OWASP Top 10 – https://owasp.org/www-project-top-ten/
- OWASP Cheat Sheet Series (Session Management, HTTP headers) – https://cheatsheetseries.owasp.org/
- Mozilla HTTP Observatory – test your website's security headers – https://developer.mozilla.org/en-US/observatory
- Internet.nl – website test (HTTPS, HSTS, IPv6, DNSSEC) – https://www.internet.nl/
- PortSwigger Web Security Academy (free, hands-on labs) – https://portswigger.net/web-security