6 / 6 · Basic
What happens when you open a web page
With a 50 ms round trip, an HTTPS page needs at least 4 round trips, 200 ms, before the first byte of HTML arrives. HTTP/3 cuts one.
Jump to the 10 practice questionsYou will learn
- Split a URL into scheme, host, path, query and fragment
- Read HTTP status codes
Before this: DNS: turning names into addresses
1Explain
The lunch menu on a crowded train
Seven forty in the morning. A student on a crowded train taps a link to the school lunch menu on mobile data, and a moment later today's menu appears. (This is a made-up scene.) In that moment the phone did everything from the last five units: a DNS lookup, a TCP connection, an encrypted session, and an HTTP request answered with a status code. Follow the phone through it and count the waits.
2Explore
First the phone reads the link
Say the link is https://www.example.com/index.html. MDN breaks a URL into parts. https is the scheme: use HTTP over an encrypted TLS connection, on port 443 unless another port is written. www.example.com is the host, the name DNS will turn into an address. /index.html is the path, the resource asked for on that server. A URL can also carry a query after a question mark and a fragment after a hash sign. The fragment points to a spot inside the page and is never sent to the server.
The URL object splits a link into its parts: scheme, host (with a port if one is written), path, query and fragment.
const u = new URL("https://www.example.com/menu?day=mon#lunch");
console.log(u.protocol);
console.log(u.host);
console.log(u.pathname);
console.log(u.search);
console.log(u.hash);https:
www.example.com
/menu
?day=mon
#lunch3Problem
/index.html
In https://www.example.com/index.html, what is /index.html?
Hint
What comes after the host.
Solution
Answer: The path
Scheme https, host www.example.com, path /index.html.
4Problem
The default HTTPS port
Which port does https:// use when no port is written?
Hint
The same as in the TCP unit.
Solution
Answer: 443
The default port for HTTPS is 443.
5Explore
Four round trips before the first byte
The time for a message to reach the server and for the reply to come back is the round-trip time (RTT). Count the round trips and you can see where the wait comes from. One: in this simplified model, count DNS as one round trip if the name is not cached. A real uncached lookup can take longer because the resolver may need to contact other servers. Two: the TCP handshake, SYN out and SYN-ACK back. Three: TLS 1.3 (RFC 8446) agrees on keys in one round trip, and the client's last handshake message can travel with the HTTP request.
Drag to turn. Scroll or pinch to zoom.
6Problem
The order of the steps
Put these in order for loading an HTTPS page.
- TCP handshake
- TLS handshake
- HTTP request and response
- DNS lookup
Hint
Name, then connection, then encryption, then the request.
Solution
Answer:
- DNS lookup
- TCP handshake
- TLS handshake
- HTTP request and response
The address comes first, then the connection, then encryption, then the request.
7Problem
HTTPS at 50 ms
RTT is 50 ms. How long before the first byte of an HTTPS page (TCP + TLS 1.3), counting the DNS lookup?
ms
Hint
Four round trips × 50 ms.
Solution
Answer: 200 ms
4 round trips × 50 ms = 200 ms.
8Problem
Cached name, 80 ms
RTT is 80 ms and the name is already cached. How long does an HTTPS page over TCP take?
ms
Hint
No DNS round trip: three left.
Solution
Answer: 240 ms
No DNS round trip: TCP + TLS + request = 3 × 80 = 240 ms.
9Explain
HTTP/3 and plain HTTP
HTTP/3 (RFC 9114) runs on QUIC (RFC 9000) instead of TCP. QUIC sits on UDP and sets up the connection and the TLS keys together, so the separate TCP round trip disappears: DNS, one handshake round trip, then the request, three in all. Plain HTTP on port 80 skips TLS and also needs three, but then anyone on the path, such as whoever runs a café's Wi-Fi, can read or change the page. The padlock in the address bar means the connection to that domain is encrypted.
10Problem
HTTP/3 at 50 ms
Same 50 ms RTT, but over HTTP/3. How long?
ms
Hint
Three round trips × 50 ms.
Solution
Answer: 150 ms
QUIC merges the transport and TLS handshakes: 3 × 50 = 150 ms.
11Problem
Under HTTP/3
Which transport does HTTP/3 run on?
Hint
QUIC sits on UDP.
Solution
Answer: QUIC over UDP
RFC 9114 maps HTTP onto QUIC (RFC 9000), which uses UDP.
12Problem
The padlock
What does the padlock in the address bar tell you?
Hint
It is about the connection, not about honesty.
Solution
Answer: The connection to that domain is encrypted
TLS protects the connection. A scam site can have a padlock too.
13Explain
The menu arrives with a number in front
The reply starts with a three-digit status code. RFC 9110 groups codes by their first digit: 1xx informational, 2xx success, 3xx redirection, 4xx client error and 5xx server error. The ones you will meet most are 200 OK, 301 Moved Permanently (the page has a new address), 404 Not Found and 500 Internal Server Error. If the school had moved the menu page, the phone would first get a 301 and then ask again at the new address. A 404 means the server answered and had nothing at that path, so the network itself was working.
14Problem
404
What does 404 mean?
Hint
4xx is a client error.
Solution
Answer: Not Found
4xx codes are client errors; 404 says the server has nothing at that path.
15Problem
Redirection
Which class of status codes means redirection?
Hint
301 belongs to it.
Solution
Answer: 3xx
RFC 9110: 3xx tells the client to look somewhere else, such as 301.
16Explain
One page, many files
The HTML is rarely the whole page. Say it mentions a style sheet, a script and five images. If the phone opened a new connection for each, every file would pay the TCP and TLS round trips again. Instead the browser keeps the connection open and sends the next requests on it, and with HTTP/2 and HTTP/3 several requests travel on one connection at the same time. Browsers also keep their own cache. When a response says it may be reused for a while, the next visit loads that file from storage without sending any request.
17Practice
Time to the first byte
Finish firstByte(rtt, kind, cached): count the round trips (DNS 1 unless cached, TCP 1 for "https" and "http", TLS 1 for "https", the QUIC handshake 1 for "http3", the request 1) and return them times rtt.
200
150
240
60function firstByte(rtt, kind, cached) {
let trips = 1;
return trips * rtt;
}
console.log(firstByte(50, "https", false));
console.log(firstByte(50, "http3", false));
console.log(firstByte(80, "https", true));
console.log(firstByte(30, "http", true));
Hint
HTTP/3 sets up the connection and the keys together, in one round trip.
A solution
function firstByte(rtt, kind, cached) {
let trips = 1;
if (!cached) trips++;
if (kind === "https" || kind === "http") trips++;
if (kind === "https") trips++;
if (kind === "http3") trips++;
return trips * rtt;
}
console.log(firstByte(50, "https", false));
console.log(firstByte(50, "http3", false));
console.log(firstByte(80, "https", true));
console.log(firstByte(30, "http", true));18Explain
Common mistakes
"The padlock means the site is safe."
The padlock only says the connection to that domain is encrypted with TLS. A scam site can have one too, so check that the domain is the one you meant.
"Incognito mode hides what I visit from my ISP and my school."
Incognito mode stops the browser keeping history and site data on your device after the session ends. Google's Chrome Help says the sites you visit, and organisations that manage your network such as a school, an employer or an internet service provider, may still be able to observe your activity. Your packets cross the same routers either way.
"A 404 means the internet is down."
A 404 is an answer from the server: it was reached and has nothing at that path. When the network really is down, no status code arrives at all.
"The part after # in a link is sent to the server."
The fragment stays in the browser and only picks a spot inside the page. It is never sent to the server.
19
Summary
- A URL has a scheme (https), a host (DNS name) and a path.
- HTTPS over TCP: DNS + TCP + TLS 1.3 + request = 4 round trips before the first byte.
- HTTP/3 over QUIC merges the handshakes: 3 round trips.
- Status codes: 2xx success, 3xx redirection, 4xx client error, 5xx server error.