Skip to content
BoKSA

05 – HTTP and the Web

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
 https://www.hva.nl:443/opleidingen/index.html?lang=en#top
 └─┬─┘   └────┬────┘└┬┘└─────────┬───────────┘└──┬──┘└┬┘
 scheme     host    port        path           query  fragment
  • 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
GET /index.html HTTP/1.1                ← request line: method, path, version
Host: www.example.com                   ← header lines
User-Agent: curl/8.14.1
Accept: text/html
Accept-Language: nl,en;q=0.8
Connection: keep-alive
                                        ← empty line = end of headers
(body – empty for GET)
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
HTTP/1.1 200 OK                         ← status line
Date: Thu, 15 Oct 2026 08:00:00 GMT
Server: nginx
Content-Type: text/html; charset=UTF-8
Content-Length: 1256
Cache-Control: max-age=3600
Last-Modified: Mon, 12 Oct 2026 10:00:00 GMT

<!doctype html><html>...               ← body
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
1. Browser → server:   GET /shop
2. Server → browser:   200 OK
                       Set-Cookie: session=8f3a9c...; Secure; HttpOnly; SameSite=Lax
3. Browser → server:   GET /cart
                       Cookie: session=8f3a9c...      ← server recognises the user

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-Since or If-None-Match with 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> 80 was used for this. Telnet still works for plain HTTP but not for HTTPS, and it is often not installed by default any more. Use curl or nc instead.

  1. Manual HTTP request with netcat (plain HTTP, on your own VM or a test site):
    1
    printf 'GET / HTTP/1.1\r\nHost: example.com\r\nConnection: close\r\n\r\n' | nc example.com 80
    
  2. With curl:
    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 support
    
    Which status code do you get from http://www.hva.nl? Why? (Hint: redirect to HTTPS.)
  3. Browser developer tools (F12 → Network tab): load a news site. How many requests? How many different domains? Which protocol column shows h2 or h3?
  4. Wireshark: capture traffic while visiting an HTTP site (e.g. http://gaia.cs.umass.edu/wireshark-labs/HTTP-wireshark-file1.html). Use the display filter http. Then do the same with an HTTPS site and filter on tls or quic. What can you still see?
  5. Test whether a site supports HTTP/3: https://http3check.net/

Check your understanding

  1. What are the parts of a URL?
  2. What is the difference between a GET and a POST request?
  3. What do status codes 301, 304, 403 and 503 mean?
  4. Why are persistent connections faster?
  5. Why are cookies needed?
  6. Name two improvements of HTTP/3 over HTTP/2.

References

Book

Videos

Articles and standards


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; includeSubDomains so browsers never use HTTP for your site again.
  • Secure cookies: set Secure (only over HTTPS), HttpOnly (not readable by JavaScript, protects against XSS) and SameSite=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