Computer Networks / Practical class / Practical class 16
Practical class · Computer Networks

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.

:ik-kitob: Practical class 16 ⏱ 2 academic hours (80 minutes) 🚇 Packet simulators ⚡ Request goes — response comes
16

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)

  1. 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:

Why is it risky to enter a password on a site opened with http://, but not with https://?

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.

Table 16.1. The most common status codes
CodeMeaningWhen you see it
200 OKSuccessThe page opened
201 CreatedA new resource was createdSigning up with POST
301 / 302Moved permanently / temporarily (with a Location header)Redirect from http:// to https://
304 Not ModifiedThe cached copy is still freshImages on a repeat visit
400 Bad RequestThe request is malformedA required field is missing
401 / 403Authentication required / no permissionNot signed in / another student’s grade
404 Not FoundThe resource was not foundA wrong link
405 Method Not AllowedThis address does not accept this methodA form needs POST instead of GET
500 / 502 / 503Internal server error / gateway error / service temporarily unavailableWhen 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

  1. Split the URL into parts

    https://hemis.adu.uz:443/dashboard?semestr=3#baholar: scheme https, host hemis.adu.uz, port 443 (if absent — 80/443 depending on the scheme), path /dashboard, query parameters semestr=3, fragment #baholar — not sent to the server, used only in the browser.

  2. 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.

  3. The request line and headers

    GET /dashboard?semestr=3 HTTP/1.1, then Host: hemis.adu.uz, Cookie: … and a blank line.

  4. 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

Request (raw text)
Response

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.

cmd — curl -v https://example.com (shortened)
*   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> …
  1. TCP connection

    Trying …:443 and Connected — the DNS reply was received, the TCP connection was established.

  2. 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).

  3. 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.

cmd — netstat -an | findstr ":443"
  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

Definition

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

:ik-noutbuk: Browser
yellow — open, green — encrypted
:ik-server: Server
The TCP connection (port 443) is established. Press “Next stage”.
Table 16.2. HTTP versions at a glance
VersionTransportMain feature
HTTP/1.1TCPText-based; connection reuse (keep-alive); requests take turns on one connection
HTTP/2TCP (in practice with TLS)Binary frames; many parallel streams on one connection (multiplexing); header compression
HTTP/3QUIC (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

ErrorConsequenceCorrect answer
Forgetting the blank line after the headersThe server does not know the headers have ended and keeps waitingAt the end of the headers \r\n\r\n
Counting Content-Length in charactersWith Uzbek/Cyrillic letters the body gets cut offlen(tana.encode("utf-8"))
Sending a password in GET query parametersThe URL is stored in server logs and browser historyConfidential data — in the POST body and only over HTTPS
“HTTPS — the site is safe, not a scam”Phishing sites get free certificates tooThe padlock only means the channel is encrypted — check the domain name
Confusing 401 and 403A wrong error message401 — “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 attackRead 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 then 200 OK and the body «Aziz» / «Malika» respectively; any other id → 404 Not Found, «Talaba topilmadi».
  • POST /login → if the body is «parol=adu2026» then 200 OK, «Xush kelibsiz»; otherwise 401 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.

Assessment criteria (individual assignment)
CriterionPoints
Requests/responses are fully assembled (screenshots or code)2
The method, status codes and headers are interpreted correctly1
The HTTPS/TLS aspect (certificate, redirect, HSTS) is analyzed1
The conclusion is well founded, the formatting is tidy1

Summary

HTTPA text request–response protocol, TCP 80, stateless.
StructureStart line → headers → blank line → body.
MethodsGET retrieves, POST sends, PUT replaces, DELETE removes, HEAD headers only.
Codes2xx ok, 3xx redirect, 4xx client, 5xx server error.
CookieSet-Cookie → Cookie: a session over stateless HTTP.
HTTPSHTTP + TLS, 443: confidentiality, integrity, authentication.
TLS 1.31-RTT handshake; everything after Hello is encrypted; the certificate chain is verified.
Toolscurl -v, F12 → Network, netstat -an, Wireshark.

Your lesson results

Your results are saved in this browser. Read all the sections and complete the exercises and assignments.

My personal notes