HTTP, HTTPS and How They Work
Every time you open a product on Uzum, pay through Payme or log in to HEMIS, your browser sends an HTTP request to a server and receives an HTTP response. Today you open and read these “letters”: the request line, headers, status codes, cookies. Then you will see in the simulator how HTTPS — that is, HTTP inside the TLS “armor” — works, what handshake lies behind the padlock icon, and you will write Python programs that analyze HTTP messages.
Lesson goals and plan
By the end of the lesson you will…
- you can read and write the structure of an HTTP request and response (start line, headers, blank line, body)
- you can distinguish the main methods (GET, POST, PUT, DELETE, HEAD) and the classes of status codes (1xx–5xx)
- you can split a URL into parts and identify the port, path and query parameters
- you can explain that HTTPS = HTTP + TLS, the stages of the TLS 1.3 handshake and the role of the certificate
- you can read the output of curl -v and netstat and analyze a connection
- you can write Python programs that parse and build HTTP messages
Plan (according to the syllabus)
- HTTP, HTTPS and How They Work
HTTP is a text protocol: a request and a response can be read with the naked eye. That is why the best way to learn it is to write and analyze messages yourself. In every task, pay attention to the blank line at the end of the lines: it marks the end of the headers :ik-quti:
With plain HTTP, your request — password, card number, message — travels across the network as plain text. On open Wi-Fi in a cafe, the person sitting next to you can read it word for word with Wireshark. With HTTPS, the same text is encrypted with TLS and reaches only the real server. Today we open up the “inner world” of both.
Key terms
Theory reminder
An HTTP message is plain text. Each line ends with \r\n (CRLF), after the headers comes a blank line, and then (if present) the body.
:ik-yuborish: Request
GET /katalog?q=telefon HTTP/1.1 Host: uzum.uz User-Agent: Mozilla/5.0 Accept: text/html Cookie: til=uz
Request line = method + path + version. A GET usually has no body.
:ik-xat: Response
HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 1532 Set-Cookie: sessiya=a8f3; HttpOnly; Secure <!doctype html>…
Status line = version + code + reason phrase. Content-Length — the size of the body in bytes.
| Code | Meaning | When you see it |
|---|---|---|
200 OK | Success | The page opened |
201 Created | A new resource was created | Signing up with POST |
301 / 302 | Moved permanently / temporarily (with a Location header) | Redirect from http:// to https:// |
304 Not Modified | The cached copy is still fresh | Images on a repeat visit |
400 Bad Request | The request is malformed | A required field is missing |
401 / 403 | Authentication required / no permission | Not signed in / another student’s grade |
404 Not Found | The resource was not found | A wrong link |
405 Method Not Allowed | This address does not accept this method | A form needs POST instead of GET |
500 / 502 / 503 | Internal server error / gateway error / service temporarily unavailable | When exam results are published |
HTTP, HTTPS and How They Work
Three sample tasks: “assembling” a request by hand, reading the output of curl -v, and watching a TLS handshake.
Sample task 1. Assemble the request yourself
- Split the URL into parts
https://hemis.adu.uz:443/dashboard?semestr=3#baholar: schemehttps, hosthemis.adu.uz, port443(if absent — 80/443 depending on the scheme), path/dashboard, query parameterssemestr=3, fragment#baholar— not sent to the server, used only in the browser. - DNS and TCP
The browser first turns the host name into an IP (lecture 15), then opens a TCP connection to port 443 of that IP (three-way handshake — lecture 12), and for HTTPS — the TLS handshake.
- The request line and headers
GET /dashboard?semestr=3 HTTP/1.1, thenHost: hemis.adu.uz,Cookie: …and a blank line. - Read the response
Status code → headers (Content-Type, Content-Length, Set-Cookie) → body.
In the “HTTP builder” below, choose the method, path and headers and see the raw request text and the training server’s response. The server has the paths /, /talabalar and /login; /login accepts only POST, and /profil requires a cookie.
:ik-asbob: HTTP builder — training server demo.adu.uz
Choose the options and press “Send”.
Sample task 2. Reading the output of curl -v
curl — a command-line tool for sending HTTP requests (built into Windows 10/11). The -v (verbose) option shows the connection and headers: > — lines you sent, < — lines the server sent, * — curl’s comments.
* Trying 93.184.215.14:443... * Connected to example.com (93.184.215.14) port 443 * TLS handshake, Client hello (1): * TLS handshake, Server hello (2): * SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384 * Server certificate: * subject: CN=www.example.org * issuer: C=US; O=DigiCert Inc; CN=DigiCert Global G2 TLS RSA SHA256 2020 CA1 > GET / HTTP/1.1 > Host: example.com > User-Agent: curl/8.4.0 > Accept: */* > < HTTP/1.1 200 OK < Content-Type: text/html < Content-Length: 1256 < Cache-Control: max-age=604800 < <!doctype html> …
- TCP connection
Trying …:443andConnected— the DNS reply was received, the TCP connection was established. - TLS
Client hello / Server hello, the agreed version (TLSv1.3) and cipher suite (AES-256-GCM). The certificate: for whom (subject) and who signed it (issuer).
- Request and response
>lines — the request, the blank>at the end — the headers are finished.<lines — the response headers. Cache-Control — how long the browser may cache this response (in seconds).
Connections can also be seen from the operating system: netstat -an shows open TCP connections.
TCP 192.168.1.105:52114 149.154.167.50:443 ESTABLISHED TCP 192.168.1.105:52130 142.250.185.78:443 ESTABLISHED TCP 192.168.1.105:52131 142.250.185.78:443 TIME_WAIT TCP 192.168.1.105:52140 195.158.31.100:443 SYN_SENT
The left column — your address and a random (ephemeral) port, the right — the server and port 443. ESTABLISHED — the connection is active, TIME_WAIT — closed but waiting for a while, SYN_SENT — a TCP connection was requested and there is no reply yet (it may signal a server or firewall problem).
Sample task 3. HTTPS and the TLS 1.3 handshake
HTTPS — a way of sending HTTP messages inside a channel protected by TLS. TLS gives three things: confidentiality (encryption — it cannot be read from outside), integrity (any change on the way is detected) and authentication (the authenticity of the server via a certificate). The structure of HTTP messages does not change — they just travel inside an encrypted “envelope”.
In TLS 1.3 the handshake finishes in one round trip (1-RTT) (in TLS 1.2 — two). Press each stage and watch what is sent and what is encrypted.
:ik-qulf: TLS 1.3 handshake simulator
| Version | Transport | Main feature |
|---|---|---|
| HTTP/1.1 | TCP | Text-based; connection reuse (keep-alive); requests take turns on one connection |
| HTTP/2 | TCP (in practice with TLS) | Binary frames; many parallel streams on one connection (multiplexing); header compression |
| HTTP/3 | QUIC (over UDP) | TLS 1.3 built in; faster connection; if a packet is lost, other streams do not stop |
Test runs: first predict, then check
Independent tasks
7 tasks: parsing and building HTTP messages. Write input() without a prompt. The list of headers ends with a blank line — just like in real HTTP.
Common mistakes
| Error | Consequence | Correct answer |
|---|---|---|
| Forgetting the blank line after the headers | The server does not know the headers have ended and keeps waiting | At the end of the headers \r\n\r\n |
| Counting Content-Length in characters | With Uzbek/Cyrillic letters the body gets cut off | len(tana.encode("utf-8")) |
| Sending a password in GET query parameters | The URL is stored in server logs and browser history | Confidential data — in the POST body and only over HTTPS |
| “HTTPS — the site is safe, not a scam” | Phishing sites get free certificates too | The padlock only means the channel is encrypted — check the domain name |
| Confusing 401 and 403 | A wrong error message | 401 — “I do not know who you are”, 403 — “I know, but you are not allowed” |
| Ignoring a certificate warning and clicking “Continue” | It opens the way to a MITM attack | Read the reason for the warning: expiry, domain, untrusted CA |
Boss level
Boss level: a mini web-server router
Input: a raw HTTP request — the request line, headers, a blank line and (for POST) a one-line body. The server’s rules:
- If the request line does not have 3 parts or there is no Host header →
400 Bad Request, body «Xato so‘rov». GET /→200 OK, body «Bosh sahifa».GET /talaba?id=N→ if id is 1 or 2 then200 OKand the body «Aziz» / «Malika» respectively; any other id →404 Not Found, «Talaba topilmadi».POST /login→ if the body is «parol=adu2026» then200 OK, «Xush kelibsiz»; otherwise401 Unauthorized, «Parol noto‘g‘ri».- Another method on an existing path (/, /talaba, /login) →
405 Method Not Allowed, «Metod mumkin emas». - Any other path →
404 Not Found, «Sahifa topilmadi».
Output: the status line, Content-Length: N (UTF-8 bytes), a blank line, the body. +60 XP
Reinforcement
Review questions
Explain the structure of an HTTP request and response.
Request: the request line (method, path, version), headers, a blank line, an optional body. Response: the status line (version, code, reason phrase), headers, a blank line, the body.
What is the difference between the GET and POST methods?
GET — retrieves a resource, the parameters are in the URL, usually no body, can be cached; POST — sends/creates data, the data is in the body.
What classes are status codes divided into?
1xx informational, 2xx success, 3xx redirection, 4xx client error, 5xx server error.
Why is HTTP called stateless, and how is a session kept?
Each request is independent; the server does not remember the previous one. A session is kept through a cookie (Set-Cookie / Cookie) or a token.
What protection does HTTPS provide?
Confidentiality (encryption), integrity (detecting changes) and server authentication (the certificate).
Name the main stages of the TLS 1.3 handshake.
ClientHello (key_share, SNI) → ServerHello (key_share) → encrypted EncryptedExtensions, Certificate, CertificateVerify, Finished → the client’s Finished → encrypted HTTP.
What is a certificate chain?
The site certificate is signed by an intermediate CA, and that one by a root CA; root certificates are pre-installed in the browser/OS and are considered trusted.
In the output of curl -v, what do the >, < and * marks mean?
> — the request lines that were sent, < — the response lines that arrived, * — curl’s comments about the connection and TLS.
Independent work
The independent-study topic in the course syllabus: “The network mechanisms of DNS, HTTP/HTTPS and modern web services.” (6 hours). Complete your variant’s task using the browser’s developer tools (F12 → Network) and curl -v; for each request, record the method, status code, main headers and size in a table.
| Criterion | Points |
|---|---|
| Requests/responses are fully assembled (screenshots or code) | 2 |
| The method, status codes and headers are interpreted correctly | 1 |
| The HTTPS/TLS aspect (certificate, redirect, HSTS) is analyzed | 1 |
| The conclusion is well founded, the formatting is tidy | 1 |
Summary
Your lesson results
Your results are saved in this browser. Read all the sections and complete the exercises and assignments.