HTTP - HyperText Transfer Protocol


Related pages
Static Badge Static Badge Static Badge
Related RFCs
Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge Static Badge


Summary

  1. Definition
  2. Requests
  3. Status codes
  4. Responses

Definition

HyperText Transfer Protocol (HTTP)
Application layer protocol that specifies how to transmit data over the Internet. HTTP is a request-response model using a client-server architecture

Key characteristics

  • Stateless protocol
  • Supports multiple versions: HTTP/1.1, HTTP/2, HTTP/3 (see below)

HTTP versions HTTP/1.1 : pipelining (asynchronous requests) HTTP/2 : multiplexing and header compression (HPACK) HTTP/3 : QUIC support (UDP-based)

Note

  • All example provided in this page can be found it the associated pcap file: Static Badge
  • This capture was generate using this Python script leveraging the scapy library.

Requests

Request definition

A request is sent by a client to a server.
The start line includes a method name, a request URI and the protocol version with a single space between each field. The following request start line specifies method GET, URI /page and protocol version HTTP/1.1:

GET /page HTTP/1.1

Requests can pass additional information using Request header fields.

Example request

Below is an example request to example.com.

GET / HTTP/1.1
Host: example.com
User-Agent: Mozilla/1.0
Accept: text/html
Connection: keep-alive


Note: There are two blank lines at the end of the request, marking the end of the request.
The subsequent response can be found in the response section.

Requests methods

MethodRFCSafeCacheable
GETRFC 9110YesYes
POSTRFC 9110NoYes
PUTRFC 9110NoNo
HEADRFC 9110YesYes
DELETERFC 9110NoNo
CONNECTRFC 9110NoNo
OPTIONSRFC 9110YesNo
TRACERFC 9110YesNo
PATCHRFC 5789NoNo
Notes:
  • A request is said safe if it does not modify server state.
  • A request is cacheable if its response may be stored by the server for future reuse.

Status codes

ClassDescription
1XXInformational - Request received and continuing
2XXSuccessful - Request accepted and processed
3XXRedirection - Further action required
4XXClient Error - Request contains error
5XXServer Error - Server failed to process request

Responses

Definition

A response is sent by the server to the client.

The start line contains:

  • Protocol version
  • Status code
  • Reason phrase (optional)

Example start line:

HTTP/1.1 200 OK

Responses may include additional response header fields

Example Response

Below is the response from the request from previous section

HTTP/1.1 200 OK
Date: Sat, 01 Jan 1970 00:00:00 GMT

Content-Type: text/html
Content-Length: 48
Connection: keep-alive

<html>
<head><title>Example</title></head>
<body>Test Page</body>
</html>

Security considerations

HTTP is generally secured through TLS, resulting in HTTPS. Other security considerations are to be bear in mind:

  • Never trust user input
  • Methods Enforcement - Restrict or disable unsafe methods (cf. request methods)
  • Security Headers - Implement headers such as Strict-Transport Security (enforces HTTPS-only), X-Frame-Options, Content-Security-Policy (enforces CSP) and X-Content-Type-Options (also see the [dedicated headers page])
  • Response Header Validation - Ensure headers do not leak sensitive informations (e.g., server software and version)
  • IP and Header Spoofing Mitigation - Validate incoming headers (cf. furnished OWASP article)

Static Badge
Static Badge
Static Badge
Static Badge
Static Badge
Static Badge