Practice: how the web works
A review of this module. Skip it if you feel confident; the next module does not need it.
Fix the mistakes
The slips that cost marks in this module. Spot each one, then check the fix.
A request fails and every error message looks alike to a beginner. Practise reading tricky URLs, placing each step of a page load, and naming the layer that broke.
Reading tricky URLs
The first example checks a tricky URL against what the server actually receives.
Example 1 · A tricky URL, checked against what is sent
# http://[::1]:8000/room.json?view=full¬e=a%26b#fees# scheme http, host ::1 (IPv6 loopback, in brackets), port 8000,# path /room.json, query view=full and note="a&b", fragment feescurl -sv "http://[::1]:8000/room.json?view=full¬e=a%26b#fees" -o room.json* Trying [::1]:8000... ... > GET /room.json?view=full¬e=a%26b HTTP/1.1 > Host: [::1]:8000 ... < HTTP/1.0 200 OK
What this code does
- curl connected straight to
[::1]:8000: an IP address needs no DNS lookup. TheHostline keeps the brackets and adds:8000because 8000 is not the default port for http. %26travelled encoded, so the server sees two parameters,viewandnote(with the valuea&b). The fragment#feeswas dropped before sending.
Most URL mistakes come from four places: a port that does not match the scheme, a special character that was not encoded, a # inside a value, and an IPv6 address without square brackets. Read every URL left to right and name each part before you trust it:
- IPv6 hosts go in brackets when a port follows:
http://[::1]:8000/. Without them, the colons are ambiguous. - A port that is not the default appears in the
Hostheader too:Host: [::1]:8000. %26inside a value is a real&; a raw&starts a new parameter.- Everything from
#on stays in the client.
From typing a URL to seeing the page
The example runs one verbose request that shows each step of the journey in its output.
Example 2 · The whole journey in one verbose request
curl -sv https://example.com -o example.html* Host example.com:443 was resolved. * IPv6: 2606:4700:10::ac42:93f3, 2606:4700:10::6814:179a * IPv4: 104.20.23.154, 172.66.147.243 * Trying [2606:4700:10::ac42:93f3]:443... * schannel: disabled automatic use of client certificate * ALPN: curl offers http/1.1 * ALPN: server accepted http/1.1 * Established connection to example.com (2606:4700:10::ac42:93f3 port 443) ... * using HTTP/1.x > GET / HTTP/1.1 > Host: example.com > User-Agent: curl/8.21.0 > Accept: */* > * Request completely sent off < HTTP/1.1 200 OK < Date: Fri, 16 Oct 2026 02:23:00 GMT < Content-Type: text/html; charset=utf-8 < Transfer-Encoding: chunked < Connection: keep-alive < Server: cloudflare ... * Connection #0 to host example.com:443 left intact
What this code does
- Step by step:
resolvedwith four addresses (DNS),Trying ...:443andEstablished connection(TCP, then TLS by Windows' schannel, which agreed on HTTP/1.1 through ALPN), the>lines (the HTTP request) and the<lines (the response). left intactis keep-alive: the connection stays open for the next request, which a browser would use for the page's script and other files.
The full journey, simplified to the steps this module covered. Each step needs the one before it:
- The browser parses the URL into scheme, host, port, path and query (and keeps the fragment to itself).
- DNS: the host name becomes an IP address, from a cache if possible, else through the resolver.
- TCP: the three-way handshake opens a connection to that address and port.
- TLS (https only): both sides compute a shared secret from their key shares, then the server sends its certificate and the browser checks it.
- HTTP: the browser sends
GET /path?querywith headers such asHost; the server answers with a status, headers and the HTML. - The browser reads the HTML and requests every CSS, script, image and API call it needs, mostly over the same kept-alive connections, then draws the page.
Order of execution
Order a page load
Tap the steps in the order a browser runs them.
Which layer failed?
The example runs one failing command for each layer, so each error message can be placed.
Example 3 · One failure per layer
curl https://shoplite-no-such-host.invalid/curl http://localhost:8000/curl --connect-timeout 5 http://10.255.255.1/curl https://expired.badssl.com/curl -s -o page.html -w "%{http_code}\n" https://example.com/index.htmlcurl: (6) Could not resolve host: shoplite-no-such-host.invalid curl: (7) Failed to connect to localhost:8000 after 2248 ms: Could not connect to server curl: (28) Connection timed out after 5005 milliseconds curl: (35) schannel: next InitializeSecurityContext failed: SEC_E_CERT_EXPIRED (0x80090328) - The received certificate has expired. 404
What this code does
- Top to bottom the failure moves up the layers: DNS (6), TCP refused (7), TCP no answer (28), TLS certificate (35), and finally HTTP, where everything worked and the server answered
404because it has no page at that path. - Only the last command got a response from a server. That single fact tells you whether to look at the network or at the request and the server.
An error message names the layer that failed. If the server sent any response, even an error page, the problem is in HTTP or the server's own work; if not, it is lower down:
- DNS: "Could not resolve host",
DNS_PROBE_FINISHED_NXDOMAIN,NXDOMAINin dig. Check the name, then the internet, thennslookup. - TCP: "connection refused" (nothing on that port), "timed out" (no answer), "connection reset" (cut off mid-way). Check the server process, port, address and firewall.
- TLS: certificate expired, wrong name, untrusted issuer, "wrong version number". Check the certificate and the scheme-port match.
- HTTP: a status such as
400,404or500came back. The connection was fine; look at the request or the server's logs.
Interview drill: "What happens when you type a URL and press Enter?"
This is one of the most common first-round questions. A good answer walks through the layers in order, names one detail per step and stops at the right depth. Practise saying it in about one minute, using a real site.
A strong outline: "The browser parses the URL. It looks up the host name in DNS, checking its caches first. It opens a TCP connection to port 443 with a three-way handshake, then does a TLS handshake where it checks the certificate. It sends an HTTP GET with the Host header. The server answers with a status, headers and HTML. The browser parses the HTML, fetches CSS, scripts and images over kept-alive connections, and draws the page."
Expect follow-ups: "What if the DNS lookup fails?", "Why is the second visit faster?" (caches and reused connections), "What does TLS protect?", "How would you see all this?" (dev tools Network tab or curl -v).
Module quiz
Questions from the whole module. Your first answer is your score.
Problems
Graded easy to hard, using everything from this module.
Try each one yourself first. Use the hint if you get stuck. Mark it as done when it works.
Exercise 1· Easy
Split each URL into scheme, host, port (write the default if none), path, query and fragment:
- (a)
http://[::1]:8000/room.json?view=full#fees - (b)
https://api.example.in/v1/trains?from=SBC&to=MAS
(a) scheme http, host ::1, port 8000, path /room.json, query view=full, fragment fees (b) scheme https, host api.example.in, port 443 (default), path /v1/trains, query from=SBC&to=MAS, fragment none
Exercise 2· Easy
Put these steps in order: (A) the browser draws the page, (B) TCP handshake, (C) DNS lookup, (D) the server sends HTML, (E) TLS handshake, (F) the browser sends GET /, (G) the browser requests CSS and images.
C, B, E, F, D, G, A
Exercise 3· Medium
Fix the encoding of each URL so the server receives exactly the values in brackets:
- (a)
https://httpbin.org/get?item=Pen & Pad[item =Pen & Pad] - (b)
https://httpbin.org/get?seat=S4#32[seat =S4#32] - (c)
https://httpbin.org/get?sum=2+3[sum =2+3]
(a) https://httpbin.org/get?item=Pen%20%26%20Pad (b) https://httpbin.org/get?seat=S4%2332 (c) https://httpbin.org/get?sum=2%2B3
Exercise 4· Medium
Check your answer to (c) of the last exercise with curl, and then send the broken version too. Copy the value of sum that httpbin returns each time.
Encoded: "sum": "2+3" Raw: "sum": "2 3"
Exercise 5· Medium
Match each message to its layer (DNS, TCP, TLS or HTTP):
- (a)
curl: (56) Recv failure: Connection reset by peer - (b)
NET::ERR_CERT_AUTHORITY_INVALID - (c)
HTTP/1.1 404 Not Found - (d)
curl: (6) Could not resolve host: api.fest.example - (e)
ERR_CONNECTION_REFUSED - (f)
curl: (35) ... wrong version number
(a) TCP (b) TLS (c) HTTP (d) DNS (e) TCP (f) TLS (https sent to a plain http port)
Exercise 6· Medium
Use one curl -sv command against https://github.com and copy one line for each of: DNS, TCP connect, the HTTP request line, the response status line, and keep-alive.
* Host github.com:443 was resolved. * Trying 20.207.73.82:443... > GET / HTTP/1.1 < HTTP/1.1 200 OK * Connection #0 to host github.com:443 left intact
Exercise 7· Hard
Your friend says: "My API at https://localhost:8080/api/marks gives curl: (35) ... wrong version number, so the server is broken." Your second test, curl http://localhost:8080/api/marks, returns [{"roll":21,"marks":88}]. Explain what is really wrong in two sentences.
The server is fine: it speaks plain http on port 8080, so https to that port fails during the TLS handshake ("wrong version number").
Use http://localhost:8080 for this local server, or configure the server with a certificate if https is needed.Exercise 8· Hard
Write your one-minute answer to "What happens when you type https://www.irctc.co.in and press Enter?" as 7 to 9 short numbered lines, naming one real detail per step (port, record, handshake message or header).
1. The browser parses the URL: scheme https, host www.irctc.co.in, default port 443, path /. 2. It checks its caches, then asks the resolver (DNS) for the IP address of www.irctc.co.in. 3. It opens a TCP connection to that address on port 443: SYN, SYN-ACK, ACK. 4. TLS handshake: client hello with the host name and a key share; the server answers with its key share, and both compute a shared secret. 5. The server sends its certificate and the browser checks name, dates and issuer; everything after this is encrypted. 6. The browser sends GET / HTTP/1.1 (or HTTP/2) with Host: www.irctc.co.in and its User-Agent. 7. The server answers with a status such as 200, headers like Content-Type: text/html, and the HTML. 8. The browser parses the HTML and requests the CSS, scripts, images and API data, reusing kept-alive connections. 9. It draws the page; scripts keep calling APIs as I search for trains.
Interview questions
Questions interviewers ask on this topic.
Finish up
Mark complete & continue
Next: Mini project: trace a web request end to end