Skip to content
Language:en Author:Laborci Gergely
http

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

$ curl -v http://localhost:8080/kurzusok/webprog -H 'Accept: text/html'
> GET /kurzusok/webprog HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/8.7.1
> Accept: text/html
>
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
< Date: Sun, 11 Oct 2026 16:45:19 GMT
< Connection: keep-alive
< Keep-Alive: timeout=5
< Transfer-Encoding: chunked
<
<h1>Webprogramozás 1.</h1>

A request can be divided into three parts:

  1. Start line: the method (GET), the path and query of the target, and the HTTP version.
  2. 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.
  3. 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:

  1. Status line: the HTTP version, the status code (200), and a short text (OK). Lesson 2.4 discusses the status codes.
  2. Headers: here, for example, Content-Type gives the format of the body, and Date the time of the response.
  3. 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:

  1. The browser sends a GET /kurzusok/webprog request; the server gives a 200 response with the HTML.
  2. 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.
  3. 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.
  • Request: start line, headers, empty line, optional body. Response: status line, headers, empty line, optional body.
  • 200 is success at the HTTP level, not necessarily business success.
  • Loading a page consists of several requests.
  • HTTP is stateless.

Review questions

  1. What parts does an HTTP request consist of?
  2. What is the Host header for?
  3. Why does the browser start several requests when opening a single page?
  4. What does it mean that HTTP is stateless?

Learning resources

Prerequisites (2)

  • client–server model
  • URL

Teaches (1)

  • HTTP