What is HTTP?

A protocol standardizes communication over the internet. The Hypertext Transfer Protocol (HTTP) is used to transfer resources (e.g., HTML files, audio files, images, etc.) between a client and a server. A client is a machine that initiates the communication, and a server is a machine that needs to be contacted. HTTP runs over TCP.

HTTP is a stateless protocol; each request must contain all the required information to fulfill the request. The server does not maintain information from prior client requests.

A simple HTTP request

An HTTP request and response follow a particular format:

  • request or response line
  • header
  • a blank line
  • an optional message body (e.g., a file)

In the following illustration, a client requests a server for index.html; the request line from the client is shown, and the server sends a response line along with the requested resource.

A client requesting index.html from the server.
A client requesting index.html from the server.

Non-persistent vs. persistent HTTP connections

Non-persistent:

TCP connections are closed after each request and response. So, for each request, a new TCP connection is opened. For example, to retrieve a web page with three images (and one base file), four TCP connections have to be opened and closed. Remember that opening TCP connections does have considerable overhead.

Persistent:

Multiple requests and responses can be sent over a single TCP connection. This reduces the overhead of repeatedly creating and closing TCP connections.

Copyright ©2024 Educative, Inc. All rights reserved