Find a course

Module 4: Core Network ServicesLesson 10 of 1312 min

HTTP, HTTPS and Loading a Web Page

Put everything together by following a web page load step by step, and learn HTTP methods, status codes, TLS certificates and the padlock.

Step 1 of 13Learn

What happens when you press Enter

Typing https://shop.example.com/cart and pressing Enter sets off a chain of everything in this course so far:

  1. DNS. The browser needs an IP address for shop.example.com. It checks its caches and, if needed, asks the resolver, which may walk the DNS hierarchy.
  2. Routing. The destination is not on your subnet, so packets go to your default gateway and then hop by hop across the internet.
  3. TCP handshake. The browser opens a connection to port 443 with SYN, SYN-ACK, ACK. (With HTTP/3, QUIC over UDP replaces this step.)
  4. TLS handshake. Client and server agree on encryption keys, and the server proves its identity with a certificate.
  5. HTTP request. The browser sends GET /cart with headers such as the browser type and cookies.
  6. HTTP response. The server returns a status code, headers and the HTML.
  7. More requests. The page references images, stylesheets and scripts, often dozens or hundreds, many from other domains, each needing DNS and connections of their own.
  8. Rendering. The browser builds and displays the page.

All this usually takes well under two seconds. Notice how many round trips are involved before the first byte of the page arrives. That's why latency, connection reuse and caching matter so much for web performance, and why content delivery networks (CDNs) place copies of sites in data centers close to users.

Step 2 of 13Practice · Put in order

Put these events in the order they happen when you open an HTTPS website for the first time.

Drag the items, or use the arrow buttons, to put them in order.

  1. DNS lookup of the site's name
  2. TCP three-way handshake with port 443
  3. Browser sends the HTTP GET request
  4. TLS handshake and certificate check
  5. Server returns a status code and the HTML

Step 3 of 13Practice · Chart

Where the time goes on a first visit to a site

Which stage takes longest here?

Tap the bar that answers the question, then press Check.

Where the time goes on a first visit to a siteBar chart with 5 categories: DNS lookup: 25 ms; TCP handshake: 30 ms; TLS handshake: 40 ms; Server builds the page: 120 ms; Download and render: 400 ms.0 ms100 ms200 ms300 ms400 msDNS lookup25 msTCP handshake30 msTLS handshake40 msServer builds the page120 msDownload and render400 ms
Illustrative numbers for a site about 30 ms away; real pages vary widely.
Where the time goes on a first visit to a site
ItemTime
DNS lookup25 ms
TCP handshake30 ms
TLS handshake40 ms
Server builds the page120 ms
Download and render400 ms

Step 4 of 13Learn

HTTP requests and responses

HTTP (Hypertext Transfer Protocol) is a request-response protocol. The client sends a request with a method, a path and headers; the server answers with a status code, headers and usually a body.

Common methods:

  • GET retrieves something: a page, an image, data. It shouldn't change anything on the server.
  • POST sends data to create or process something: submitting a form, placing an order.
  • PUT and PATCH update existing resources; DELETE removes one. These are common in web APIs.

Status codes are grouped by their first digit:

RangeMeaningExamples
1xxinformational101 Switching Protocols
2xxsuccess200 OK, 201 Created, 204 No Content
3xxredirection301 Moved Permanently, 302 Found, 304 Not Modified
4xxclient error400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests
5xxserver error500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout

The first digit tells you who to look at. A 4xx means the request was the problem: wrong URL, missing login, not allowed. A 5xx means the server failed while handling a valid request. A 502 or 504 often means a proxy or load balancer in front of the site couldn't get a good answer from the application server behind it.

HTTP is stateless: each request stands alone. Logins and shopping carts work by having the browser send a cookie or token with every request.

Step 5 of 13Practice · Sort into groups

Sort each status code by what it tells you.

Tap an item, then tap its group (or drag it there).

Step 6 of 13Learn

HTTPS, TLS and certificates

Plain HTTP sends everything as readable text. Anyone on the path, on public Wi-Fi, at a provider or on a compromised router, could read passwords or change the page. HTTPS is HTTP inside TLS (Transport Layer Security), which provides three guarantees:

  • Confidentiality. Traffic is encrypted, so eavesdroppers see only scrambled data. They can still see which server you connect to, but not the pages or form contents.
  • Integrity. Any tampering with the data in transit is detected.
  • Authentication. The server proves it really is shop.example.com with a certificate.

A certificate binds a domain name to a public key and is signed by a certificate authority (CA) that browsers trust. During the TLS handshake the browser checks that the certificate is for the exact name in the address bar, hasn't expired and chains back to a trusted CA. If any check fails, you see a full-page warning. Free automated CAs made certificates available to every site, and today the large majority of web traffic is encrypted.

What the padlock does not mean: that the site is honest. A phishing site at examp1e-login.com can get a valid certificate for its own name. The padlock tells you the connection is private and that you're talking to the domain shown, so always read the domain itself.

Step 7 of 13Practice · Select all that apply

What does HTTPS protect against? Select all that apply.

Select all that apply.

Step 8 of 13Practice · Diagram

A TLS handshake, simplified

At which step would a fake site impersonating your bank usually be caught?

Tap the shape that answers the question, then press Check.

A TLS handshake, simplifiedProcess diagram: Client hello → Server hello + certificate → Browser checks the certificate → Key exchange → Encrypted HTTP.Client helloServer hello +certificateBrowser checks thecertificateKey exchangeEncrypted HTTP
Client hello

Browser lists the TLS versions and ciphers it supports.

Server hello + certificate

Server picks settings and sends its certificate.

Browser checks the certificate

Right name, not expired, signed by a trusted authority.

Key exchange

Both sides derive the same session keys without sending them.

Encrypted HTTP

Requests and responses now travel encrypted.

Step 9 of 13Note

Step 10 of 13Practice · Fill in the blanks

Fill in the blanks

A browser shows "404" when the server could not find the requested page; this is a error. A "503" means the is temporarily unable to handle the request.

Step 11 of 13Diagram

HTTP status code families

HTTP status code familiesHierarchy diagram: Status codes, 2xx Success, 200 OK, 3xx Redirect, 301 Moved Permanently, 4xx Client error, 403 Forbidden, 404 Not Found, 5xx Server error, 500 Internal Server Error, 503 Service Unavailable.Status codes2xx Success200 OK3xx Redirect301 Moved Permanently4xx Client error403 Forbidden404 Not Found5xx Server error500 Internal Server Error503 Service Unavailable
Status codes
2xx Success
200 OK
3xx Redirect
301 Moved Permanently
4xx Client error
403 Forbidden
404 Not Found
5xx Server error
500 Internal Server Error
503 Service Unavailable

Step 12 of 13Practice · Choose one

Which HTTP method is normally used to submit a sign-up form that creates a new account?

Step 13 of 13Practice · What would you do?

What would you do?

Your company's website suddenly shows "502 Bad Gateway". The site runs behind a load balancer that forwards requests to two application servers. What is the most useful first check?