Sub topic 2
Securing the Connection with TLS
Assume you know basic HTML, IP addresses, and how to use browser developer tools. This chapter follows the stages after a browser has found the server's IP address.
TLS protects the connection
For an https URL, the browser first opens a TCP connection. It then performs a TLS handshake. TLS, or Transport Layer Security, encrypts data and verifies the server's identity.
The handshake usually works like this:
- The browser sends a
ClientHellowith supported TLS versions and cryptographic options. - The server sends a
ServerHello, its certificate, and key-exchange data. - The browser checks that the certificate is trusted and matches the host name.
- Both sides derive shared encryption keys.
- They exchange encrypted
Finishedmessages.
After this, HTTP data travels inside the encrypted TLS connection. Network observers can usually see the destination address and traffic size, but not the URL path, headers, or page content.
Sending HTTP and reading the response
Once TLS is ready, the browser sends an HTTP request:
GET /docs/intro?lang=en HTTP/1.1
Host: example.com
Accept: text/htmlThe server returns a response containing a status line, headers, and often a body:
HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Cache-Control: max-age=3600
<!doctype html>
<html>...</html>The status code tells the browser what happened. Headers describe the body, caching rules, cookies, and other behavior.
Redirects and status codes
A redirect does not move the browser directly to a new page. The server returns a response such as 301, 302, or 307 with a Location header. The browser then makes another request.
| Code | Meaning | Typical result |
|---|---|---|
| 200 | Success | Process the response |
| 301 or 302 | Redirect | Request the `Location` URL |
| 404 | Resource missing | Show an error page |
Caching avoids repeat requests
Before sending a request, the browser may use a fresh cached response. Cache-Control: max-age=3600 allows reuse for one hour. If the entry is stale, the browser can send a conditional request with If-None-Match. A 304 Not Modified response tells it to reuse the cached body.
Exercise
Why can one page navigation involve several HTTP requests?
Show answer
The main document may redirect, and its HTML can reference CSS, JavaScript, images, and fonts that require separate requests.