By the end of the lesson, you can read the parts of an HTTP request and response, say what the role of the start line, the headers, and the body is, and understand why opening a page is not made up of a single request.
Why do we need a common message format?
The browser and the server never meet by prior arrangement: one company wrote the browser, another wrote the server, and yet they understand each other exactly. This is only possible if the form of the messages is standardized. HTTP provides this common form: what a request must contain, and what parts a response consists of.
HTTP is stateless: it handles every request on its own, and at the protocol level the server does not remember what was requested before. How we nevertheless "stay logged in" is explained in chapter 7.
Opening a page
The student opens the address https://kurzuspont.example/kurzusok/webprog. The browser, as a client, sends a request, and the server gives a response:
sequenceDiagram
actor H as Student
participant B as Browser
participant S as Web service
H->>B: Open the course page
B->>S: HTTP request for the resource
S-->>B: HTTP response
B-->>H: Display the result
HTTP is not used only by browsers: a mobile app, a command-line tool, or another server can also send an HTTP request. The roles always refer to the concrete exchange of messages.
The parts of a request
The following is a real request sent with the curl command-line tool. The output comes from a test server running on the machine, which is a small model of Kurzuspont; lines marked > show the outgoing request, lines marked < show the header of the response:
Start line: the method (GET), the path and query of the target, and the HTTP version.
Headers: name–value pairs. Host says which host the request is for (so one machine can serve several names), User-Agent identifies the client, and Accept indicates the desired response format.
Empty line, then body: an empty line marks the end of the headers. A usual GET request has no body.
The parts of a response
The structure of the response is similar:
Status line: the HTTP version, the status code (200), and a short text (OK). Lesson 2.4 discusses the status codes.
Headers: here, for example, Content-Type gives the format of the body, and Date the time of the response.
Empty line, then body: the actual content, here an HTML fragment.
200 only means that the HTTP request was successful at the protocol level, not that everything is also fine from a business point of view.
flowchart TB
subgraph Request
K1[Start line: method, target, version] --> K2[Headers]
K2 --> K3[Empty line]
K3 --> K4[Body, if any]
end
subgraph Response
V1[Status line: version, status code] --> V2[Headers]
V2 --> V3[Empty line]
V3 --> V4[Body, if any]
end
One page can involve several requests
The user sees one page, but the initial HTML can refer to further resources: style sheets, images, fonts, programs. The browser downloads these with separate HTTP requests. So opening a page is not necessarily a single conversation.
flowchart LR
H[Request the HTML] --> D[HTML response]
D --> C[Request the style sheet]
D --> K[Request the image]
D --> J[Request the program]
The separate requests can go to the same or to other services. The network panel (Network) found in the developer tools of browsers (Chrome, Firefox, Edge, and Safari also has one) shows exactly this list; it is worth looking once at how many requests the loading of a well-known page consists of.
HTTP and HTTPS
In the address, http:// or https:// indicates the way of access. HTTPS is the same HTTP, but over a protected (encrypted and authenticated) connection. The basic request–response pattern does not change, only the connection is protected. Chapter 4 discusses how the protection works and where its limits are. The existence of HTTPS alone does not prove that the content is true or that the provider is trustworthy.
Worked example: loading the course page
Loading the course page of Kurzuspont goes like this:
The browser sends a GET /kurzusok/webprog request; the server gives a 200 response with the HTML.
Reading the HTML, the browser notices that a style sheet, a program, and a logo are also needed, and sends further GET requests for them.
If the student later clicks the "Enrol" button, the browser starts a new request (with POST, according to lesson 2.3).
All three steps use the same form: start line, headers, body. This common form is the strength of HTTP.
Common misconceptions
Statement
Clarification
"HTTP is only needed for HTML pages."
Images, data, and other resources can also be transferred with it.
"Opening a page is a single request."
The document can start further resource requests.
"200 means everything is fine."
It only signals success at the HTTP level.
"HTTPS is a different request–response model."
It is the same HTTP, over a protected connection.
"The server remembers me from the previous request."
HTTP is stateless; memory is provided by separate solutions.
In brief
HTTP is a common message format between the client and the server.
The HTTP request and response
Objectives
By the end of the lesson, you can read the parts of an HTTP request and response, say what the role of the start line, the headers, and the body is, and understand why opening a page is not made up of a single request.
Why do we need a common message format?
The browser and the server never meet by prior arrangement: one company wrote the browser, another wrote the server, and yet they understand each other exactly. This is only possible if the form of the messages is standardized. HTTP provides this common form: what a request must contain, and what parts a response consists of.
HTTP is stateless: it handles every request on its own, and at the protocol level the server does not remember what was requested before. How we nevertheless "stay logged in" is explained in chapter 7.
Opening a page
The student opens the address
https://kurzuspont.example/kurzusok/webprog. The browser, as a client, sends a request, and the server gives a response:sequenceDiagram actor H as Student participant B as Browser participant S as Web service H->>B: Open the course page B->>S: HTTP request for the resource S-->>B: HTTP response B-->>H: Display the resultHTTP is not used only by browsers: a mobile app, a command-line tool, or another server can also send an HTTP request. The roles always refer to the concrete exchange of messages.
The parts of a request
The following is a real request sent with the
curlcommand-line tool. The output comes from a test server running on the machine, which is a small model of Kurzuspont; lines marked>show the outgoing request, lines marked<show the header of the response:A request can be divided into three parts:
GET), the path and query of the target, and the HTTP version.Hostsays which host the request is for (so one machine can serve several names),User-Agentidentifies the client, andAcceptindicates the desired response format.The parts of a response
The structure of the response is similar:
200), and a short text (OK). Lesson 2.4 discusses the status codes.Content-Typegives the format of the body, andDatethe time of the response.200only means that the HTTP request was successful at the protocol level, not that everything is also fine from a business point of view.flowchart TB subgraph Request K1[Start line: method, target, version] --> K2[Headers] K2 --> K3[Empty line] K3 --> K4[Body, if any] end subgraph Response V1[Status line: version, status code] --> V2[Headers] V2 --> V3[Empty line] V3 --> V4[Body, if any] endOne page can involve several requests
The user sees one page, but the initial HTML can refer to further resources: style sheets, images, fonts, programs. The browser downloads these with separate HTTP requests. So opening a page is not necessarily a single conversation.
flowchart LR H[Request the HTML] --> D[HTML response] D --> C[Request the style sheet] D --> K[Request the image] D --> J[Request the program]The separate requests can go to the same or to other services. The network panel (Network) found in the developer tools of browsers (Chrome, Firefox, Edge, and Safari also has one) shows exactly this list; it is worth looking once at how many requests the loading of a well-known page consists of.
HTTP and HTTPS
In the address,
http://orhttps://indicates the way of access. HTTPS is the same HTTP, but over a protected (encrypted and authenticated) connection. The basic request–response pattern does not change, only the connection is protected. Chapter 4 discusses how the protection works and where its limits are. The existence of HTTPS alone does not prove that the content is true or that the provider is trustworthy.Worked example: loading the course page
Loading the course page of Kurzuspont goes like this:
GET /kurzusok/webprogrequest; the server gives a200response with the HTML.GETrequests for them.POST, according to lesson 2.3).All three steps use the same form: start line, headers, body. This common form is the strength of HTTP.
Common misconceptions
In brief
200is success at the HTTP level, not necessarily business success.Review questions
Hostheader for?Learning resources