What is HTTP (Hypertext Transfer Protocol)?

The application-layer protocol for exchanging HTML, images and data between web browsers and web servers, among others. A client sends a request made up of a method, a URL, headers and a body, and the server returns a response made up of a status code, headers and a body. As a protocol it is stateless, so state such as a login is kept with cookies and similar means. HTTP/1.1 uses a text format and persistent connections, HTTP/2 multiplexes several streams over one TCP connection, and HTTP/3 runs over QUIC on UDP. HTTP protected by TLS is called HTTPS.

Japanese name: HTTP

HTTP (Hypertext Transfer Protocol) appears in 16 practice questions across 3 topics, including Web Technology Basics, Computer Networking Basics, Cloud and Container Basics.

Field: Web Technology Basics

Shape of requests and responses

A request consists of a request line such as "GET /index.html HTTP/1.1", headers such as Host and Accept, a blank line and a body, in that order. A response consists of a status line such as "HTTP/1.1 200 OK", headers such as Content-Type and Cache-Control, and a body. Headers take the form "Name: value" and convey the type of the body, how it may be cached, authentication information, the compression method and so on.

Differences between versions

In HTTP/1.1, persistent connections that reuse one TCP connection are the default, but responses on one connection are received one at a time in order. HTTP/2 splits messages into binary frames, multiplexes several requests and responses over one connection and also compresses headers. HTTP/3 uses QUIC over UDP as its transport, which reduces the problem of a packet loss stalling unrelated streams and also cuts the round trips needed to set up a connection.

Statelessness and managing state

HTTP is a stateless protocol that handles each request independently. Because the server does not have to remember earlier requests, the load is easy to spread over many servers. State such as a login is kept on the application side, for example by passing a session ID issued by the server in a cookie, or by sending a signed value in the Authorization header.

Try it: questions about HTTP (Hypertext Transfer Protocol)

Which of the following does HTTPS (HTTP protected by TLS) protect?

  1. AThat the operator of the website you connect to is a trustworthy person or organization without malicious intent
  2. BThat the fact you are communicating, and the IP address of the server you connect to, cannot be seen along the path
  3. CThat the content cannot be read or altered in transit, and that the server you connect to is the legitimate holder of the domain name in its certificate
Show answer and explanation

Answer: C. That the content cannot be read or altered in transit, and that the server you connect to is the legitimate holder of the domain name in its certificate

TLS provides three things: encryption of the communication (confidentiality), detection of tampering (integrity) and authentication of the server. The server presents a certificate, and the browser checks it by following signatures back to a certificate authority (CA) it trusts and confirms that it matches the domain name in the URL. What this proves, however, is only that you are talking to the holder of that domain name; it says nothing about whether the site's operator is honest. Even a scam site can obtain a certificate for its own domain. Also, the IP header is not encrypted, so which IP address you talk to, when and how much can be seen along the path.

Which of the following correctly lists the elements in the first line (the request line) of an HTTP/1.1 request?

  1. AThe method, the request target (such as a path) and the HTTP version
  2. BThe HTTP version, the status code and a short reason phrase
  3. CThe source IP address, the destination port number and the method
Show answer and explanation

Answer: A. The method, the request target (such as a path) and the HTTP version

An HTTP request consists of the request line, the headers (one "Name: value" per line), a blank line and the body, in that order. For example, "GET /docs/index.html HTTP/1.1" is a line that requests /docs/index.html with the GET method. In HTTP/1.1 the Host header must also be sent, so that the server can tell which site a request is for even when several sites are run on the same IP address. The first line of a response is the status line, which lists the version, the status code and the reason phrase, as in "HTTP/1.1 200 OK".

FAQ

What is the difference between HTTP and HTTPS?

HTTPS encrypts HTTP exchanges with TLS and adds tamper detection and server authentication. Requests and responses have the same form as in HTTP, and the default port numbers are 80 for HTTP and 443 for HTTPS. Websites generally use HTTPS to protect passwords and cookies.

How are GET and POST used differently?

GET is the method for retrieving a resource. It is treated as "safe", meaning it does not change the server's state, so browsers and caches may send it repeatedly or store the result. POST is used when the server is asked to process something or register data, as with an order or a post. The query of a GET request goes into the URL and remains in access logs and browsing history, so secret information such as passwords should not be put there.

HTTP (Hypertext Transfer Protocol) in the explanations

Questions that mention HTTP (Hypertext Transfer Protocol) (16)

  1. Which of the following does HTTPS (HTTP protected by TLS) protect?
  2. Which of the following correctly lists the elements in the first line (the request line) of an HTTP/1.1 request?
  3. Which of the following correctly describes HTTP/2 and HTTP/3?
  4. HTTP is a stateless protocol. Which of the following correctly describes what this means together with the usual way a website keeps a user logged in?
  5. A merchant's server wants to know immediately when a payment is completed on an online payment service. Which of the following correctly describes the method in which the payment service sends a notification by HTTP POST to a URL the merchant registered in advance (a webhook)?
  6. 1.5 MB of text data is compressed with gzip to one third of its size and sent. The bandwidth is 10 Mbps and the RTT is 100 ms, and before the data starts to be sent, the TCP connection, the TLS handshake and the HTTP request take three round trips in total. Assume 1 MB = 10^6 bytes, and ignore compression and decompression time, headers and waiting caused by TCP congestion control. Which of the following is closest to the time until all the data has been received?
  7. Cloud storage is used for three purposes: (1) attaching it to a virtual machine as a disk, creating a file system and storing database data files; (2) mounting it from several servers at the same time and using it as a shared directory; (3) reading and writing a large number of images by key (name) through an HTTP API and growing the capacity without deciding it in advance. Which of the following is the appropriate combination of storage types for (1) to (3)?
  8. In the four-layer TCP/IP model, which layer do TCP and UDP belong to?
  9. Which correctly describes UDP?
  10. A client makes a new HTTPS connection (TLS 1.3 over TCP) to a web server with a round-trip time (RTT) of 100 ms. Roughly how long does it take until the response to the first request starts to arrive? Assume DNS resolution is already done, and ignore server processing time and data transfer time.
  11. Which correctly pairs protocols with the standard port numbers their servers use?
  12. From a web server with an RTT of 40 ms, one HTML file and the four images it references are fetched one after another. Assume that establishing a TCP connection takes one round trip and each request and response take one round trip, and ignore data transfer time, server processing time, TLS and connection teardown. Which of the following is the difference in total time between opening a new TCP connection for each object and reusing one TCP connection (a persistent connection)?
  13. A chat app needs to deliver new messages from the server to the browser immediately. Which of the following correctly describes WebSocket?
  14. A web system is built in three tiers: a web server, an application server and a database server. Which of the following is the processing that the application server mainly handles?
  15. In a Kubernetes cluster, HTTPS requests arriving for one host name should be routed to the api Service if the path begins with /api, and to the web Service otherwise. Which of the following resources is suitable for defining this routing rule?

Books on Web Technology Basics Ad

As an Amazon Associate I earn from qualifying purchases.

Related terms

TLS DNS (Domain Name System) Pod HTTP status code Cookie (HTTP cookie) Object storage OSI reference model Three-way handshake Port number SSH

Back to the glossary