Sobes.tech
Middle

How is HTTP/1.x structured: request, response, headers, body, statelessness?

sobes.tech AI

Answer from AI

HTTP/1.x is a hypertext transfer protocol based on a request-response model.

Request: The client sends a request to the server, which consists of:

  • A start line (method, URI, protocol version), for example: GET /index.html HTTP/1.1
  • Headers (key: value), for example: Host: example.com
  • An empty line separating headers from the body
  • Body (optional), for example, form data in POST requests

Response: The server responds with a similar structure:

  • A start line with a status code, for example: HTTP/1.1 200 OK
  • Headers
  • An empty line
  • Response body (e.g., HTML page)

Headers convey meta-information, such as content type (Content-Type), body length (Content-Length), cookies, etc.

Statelessness: HTTP/1.x is a stateless protocol, meaning each request is processed independently, and the server does not store information about previous requests. Mechanisms like cookies or sessions are used to maintain state.

Example request:

GET /page HTTP/1.1
Host: example.com
User-Agent: curl/7.68.0

Example response:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 125

<html>...</html>