Computer Engineering is coming soon

We're still writing and reviewing the notes for every subject, and we'll open it when every subject is ready. Meanwhile you can practise aptitude, ask Aria about any subject, or see the branches that are ready.

HTTP and the web

Clear, exam-focused notes on HTTP and the web: protocol basics, message formats, caching, cookies, performance calculations (RTT and download time), security (HTTPS/TLS), proxies and CDNs, with worked examples and exam tips.

Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.

Why it matters

Two or three sentences: where an engineer uses this.

The web is the dominant application on computer networks; engineers build, debug and optimise web services, proxies and CDNs and must understand how the Hypertext Transfer Protocol (HTTP) works. Knowing HTTP lets you reason about latency, caching, security (HTTPS/TLS), and how browsers and servers interact — essential for network design, performance tuning and secure deployment.

Key ideas

Explain from first principles. Define terms before use.

  • Web: the system of interlinked documents and resources, identified by addresses and retrieved by network protocols. In practice this means HTML pages and other resources served over HTTP.
  • HTTP (Hypertext Transfer Protocol): an application-layer request–response protocol used by clients (usually browsers) and servers to exchange resources identified by URIs. HTTP runs over TCP (or QUIC in HTTP/3) and is stateless by design.
  • URI (Uniform Resource Identifier): a string that identifies a resource. A URL (Uniform Resource Locator) is a URI that gives the location (scheme, host, path) used to retrieve the resource.

Basic operation (from first principles):

  1. Client resolves host name via DNS to an IP address (DNS is a separate application-layer service). Draw: client -> DNS server (label: domain name query/response).
  2. Client opens a transport connection (usually TCP) to server IP and port (default port for HTTP is 80, HTTPS is 443). Draw: client -> server, label: TCP handshake (SYN, SYN-ACK, ACK) if using TCP.
  3. Client sends an HTTP request message; server sends an HTTP response message; connection may be closed or reused depending on HTTP version and headers. Draw arrows labelled with "HTTP request" and "HTTP response".

HTTP message structure and rules (exact definitions):

  • Request line: Method SP Request-URI SP HTTP-Version CRLF where SP = space, CRLF = \r\n. The method and URI determine the operation.
  • Response status line: HTTP-Version SP Status-Code SP Reason-Phrase CRLF.
  • Header fields: zero or more lines Header-Name: SP Header-Value CRLF. Header names are case-insensitive. There is a blank line (CRLF) after headers, then the message-body (if any).
  • Methods: define operations. Important ones: GET (retrieve a representation; should be safe and idempotent), POST (send data causing side-effects; not necessarily idempotent), PUT (store/replace a resource; idempotent), DELETE (remove resource; idempotent), HEAD (like GET but no body), OPTIONS (query server capabilities). Define idempotent: multiple identical requests produce same effect as one.
  • Status codes: three-digit code grouped by class: 1xx informational, 2xx success (200 OK), 3xx redirection (301 Moved Permanently, 302 Found), 4xx client error (404 Not Found, 403 Forbidden), 5xx server error (500 Internal Server Error). State: class is first digit.

Caching and conditional requests (definitions and rules):

  • Cache: a storage holding responses to reuse later. Common caches: browser cache, proxy cache, CDN edge cache.
  • Cache-control rules (important headers): Cache-Control, Expires, ETag, Last-Modified, If-Modified-Since, If-None-Match.
  • Conditional GET: client sends If-Modified-Since or If-None-Match; server returns 304 Not Modified when resource unchanged to save bandwidth.

Cookies and sessions:

  • Cookie: a small piece of data server asks client to store (Set-Cookie header). Sent back by client in Cookie header on subsequent requests to the same origin (subject to path, domain and security attributes). Cookies allow the server to maintain state across otherwise stateless HTTP requests.

Persistent connections and pipelining:

  • Persistent connection (HTTP/1.1 default): keep TCP connection open for multiple request–response pairs to reduce handshake overhead.
  • Pipelining: sending multiple requests without waiting for responses on the same connection (supported by HTTP/1.1 but poorly adopted in browsers and often disabled). HTTP/2 replaced pipelining with multiplexing.

HTTP versions and modern developments:

  • HTTP/1.0: no persistent connections by default.
  • HTTP/1.1: persistent connections by default, chunked transfer encoding, host header required.
  • HTTP/2: uses a binary framing layer, multiplexes streams over single TCP connection, header compression (HPACK), server push.
  • HTTP/3: runs over QUIC (a transport built on UDP), provides connection migration and reduced latency for new connections.

Security (HTTPS):

  • HTTPS denotes HTTP over TLS (Transport Layer Security). TLS provides confidentiality, integrity and server authentication (and optionally client auth). TLS handshake precedes HTTP exchange (or is integrated, e.g. TLS 1.3) and typically adds one or more RTTs before application data.

Proxies, gateways, and CDNs:

  • Proxy: an intermediary that forwards requests; can be forward proxy (client config) or reverse proxy (server side). A CDN (Content Delivery Network) is a geographically distributed cache system improving latency and load.

Diagrams to draw in exams: draw a timeline showing client DNS lookup, TCP handshake (SYN, SYN-ACK, ACK), HTTP request, HTTP response. Label RTTs and show where TLS handshake fits.

Formulas

For HTTP performance, simple formulas used in exam numericals.

T_total_nonpersistent = N * (RTT_handshake + RTT_request) + Σ (object_size_i / bandwidth)

  • where N = number of TCP connections (often equals number of objects when non-persistent), RTT_handshake = 1·RTT for TCP three-way handshake (time for SYN->SYN-ACK->ACK), RTT_request = 1·RTT for request–response roundtrip, object_size_i in bits, bandwidth in bits/s. Units: seconds.

T_total_persistent = RTT_handshake + N * RTT_request + Σ (object_size_i / bandwidth)

  • where persistent connection reuses one TCP handshake (RTT_handshake usually 1 RTT) and each request still requires ~1 RTT unless pipelined or multiplexed.

transmission_time = object_size / bandwidth (seconds)

  • object_size in bits, bandwidth in bits/s.

Note: when TLS is used, add RTT_tls for handshake costs (typically ~2 RTTs for a full TLS 1.2 handshake, ~1 RTT for TLS 1.3, and 0–1 RTT with session resumption/0-RTT where supported).

HTTP message syntax to remember (exact):

  • Request line example: GET /path/index.html HTTP/1.1 (then CRLF, headers, blank line, optional body).
  • Status line example: HTTP/1.1 200 OK.
  • Header example: Content-Type: text/html; charset=utf-8.

Worked examples

Two exam-standard examples with steps and units.

Example 1 — performance numeric (multiple objects): Question: A web page has an HTML file (100 kB) and 5 images each 200 kB. RTT between client and server = 50 ms. Bandwidth = 10 Mbps (10 × 10^6 bits/s). Assume non-persistent HTTP where each object requires a new TCP connection and ignore DNS and TLS. Compute total time to download all objects.

Step 1: convert sizes to bits.

  • HTML size = 100 kB = 100 × 1024 bytes = 102400 bytes = 102400 × 8 = 819200 bits.
  • Each image = 200 kB = 200 × 1024 bytes = 204800 bytes = 204800 × 8 = 1638400 bits.

Step 2: transmission times.

  • t_html = 819200 / (10×10^6) = 0.08192 s.
  • t_image = 1638400 / (10×10^6) = 0.16384 s per image.

Step 3: RTTs for non-persistent: each object requires handshake + request-response = 2 RTTs = 2 × 0.05 = 0.1 s.

  • Number of objects N = 1 HTML + 5 images = 6.

Step 4: total time = N * 0.1 s + t_html + 5 × t_image = 6 × 0.1 + 0.08192 + 5 × 0.16384 = 0.6 + 0.08192 + 0.8192 = 1.50112 s.

Answer: 1.50 s (approx).

Example 2 — HTTP message construction and Content-Length: Question: Compose an HTTP/1.1 POST request to /submit on host example.com with body name=Aria&roll=42. Show Content-Length and headers.

Step 1: compute body length in bytes: string name=Aria&roll=42 has 17 characters = 17 bytes (ASCII), so Content-Length: 17.

Step 2: request lines (CRLF represented as new line here):

  • POST /submit HTTP/1.1
  • Host: example.com
  • Content-Type: application/x-www-form-urlencoded
  • Content-Length: 17
  • blank line
  • name=Aria&roll=42

Explain: server will read 18 bytes from body. If Content-Length omitted for POST (and no chunked encoding), server cannot know body length and may wait.

Example 3 — trace of a conditional GET: Question: Client has cached resource with ETag "v5". It sends a conditional GET. Show request and server response when resource unchanged.

Client request headers include: If-None-Match: "v5". Server checks and finds resource unchanged → responds HTTP/1.1 304 Not Modified with no body and possibly updated headers. Client uses cached copy.

Common mistakes

  • Counting RTTs incorrectly: forgetting TCP handshake RTT or TLS handshake RTT when computing total time.
  • Believing cookies are encrypted or secure by default; cookies are not encrypted—only HTTPS encrypts them in transit. The Secure attribute restricts cookies to HTTPS, HttpOnly prevents JavaScript access, and SameSite controls cross-site sending.
  • Confusing persistent connection with HTTP/2 multiplexing (persistent means reusing TCP; multiplexing allows multiple simultaneous streams).
  • Assuming 200 OK means fresh copy: 304 Not Modified indicates cache hit with conditional request.
  • Writing headers without the blank line before the body.

For your exam

Kinds of questions produced and what full-marks answers include:

  • Definitions and short notes: define HTTP, URL, GET/POST, persistent connection, caching headers (Cache-Control, ETag). Full marks require concise definition plus short example.
  • Derivations and diagrams: show timeline diagrams of DNS, TCP handshake, HTTP request/response, label RTTs. Full marks need correct sequence and labels.
  • Numericals: compute download time with given RTT and bandwidth (persistent vs non-persistent). Full marks require conversions (kB→bytes→bits), formula use, units in each step and final numeric answer.
  • Message construction: write a correct HTTP request or response, include required headers (Host for HTTP/1.1) and correct body delimiting (Content-Length or Transfer-Encoding: chunked), and CRLF structure. Full marks need exact request/status line and headers with blank line then body.
  • Theory/essay: explain caching, conditional GET, and how CDN reduces latency. Full marks need clear definitions, examples and mention of headers and their effects.

Quick check

  1. What header does a server send to create a cookie?
  2. What HTTP status class indicates redirection?
  3. Name one difference between HTTP/1.1 and HTTP/2.

Answers: Set-Cookie; 3xx; HTTP/2 uses binary framing and multiplexes multiple streams over one TCP connection (while HTTP/1.1 is text-based and requests are ordered).

Finished this topic? Mark it so your progress, study plan and readiness keep up.

Stuck on something here?