Message Syntax

This page covers the wire-level structure of HTTP/1.1 messages as defined by RFC 9112 (HTTP/1.1 Message Syntax and Routing).

General Message Format

Every HTTP/1.1 message — whether request or response — follows the same structure:

start-line CRLF
*( header-field CRLF )
CRLF
[ message-body ]

The start-line is either a request-line or a status-line. Headers follow as field-name: field-value pairs, each terminated by CRLF. An empty line (bare CRLF) separates headers from the optional body.

Request Message

method SP request-target SP HTTP-version CRLF
*( field-name ":" OWS field-value OWS CRLF )
CRLF
[ message-body ]

Example — a POST with a JSON body:

POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/json
Content-Length: 27

{"name":"Alice","age":30}

Key rules (RFC 9112 §3):

  • Exactly one SP (space, 0x20) between method, request-target, and HTTP-version.
  • The request-target is usually an absolute path (/index.html) or an asterisk (*) for OPTIONS.
  • The HTTP-version MUST be HTTP/1.1 (or HTTP/1.0 for legacy).
  • The request-line MUST end with CRLF. No extra whitespace, no trailing characters.

Response Message

HTTP-version SP status-code SP [ reason-phrase ] CRLF
*( field-name ":" OWS field-value OWS CRLF )
CRLF
[ message-body ]

Example:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 1234
Cache-Control: max-age=3600

<!DOCTYPE html>...

The reason-phrase (e.g., OK, Not Found) is purely informational — clients MUST NOT depend on its content. HTTP/2 and HTTP/3 removed it entirely.

Methods

HTTP/1.1 defines a set of request methods that indicate the desired action on a resource:

MethodSafeIdempotentPurpose
GETYesYesRetrieve a representation of the resource.
HEADYesYesSame as GET but without the response body. Used to check headers/existence.
POSTNoNoSubmit data to the resource. Often creates a new sub-resource or triggers processing.
PUTNoYesReplace the target resource entirely with the request payload.
DELETENoYesRemove the target resource.
PATCHNoNoApply a partial modification to the resource (RFC 5789).
OPTIONSYesYesDescribe the communication options for the target resource. Used in CORS preflight.
TRACEYesYesEcho back the received request. Useful for debugging proxies. Often disabled for security.
CONNECTNoNoEstablish a tunnel to the server, typically for HTTPS through a proxy.

Safe vs Idempotent

  • Safe methods do not modify server state. A GET request should never create, update, or delete a resource. Caches and prefetchers rely on this guarantee.
  • Idempotent methods produce the same result whether called once or many times. PUT /user/1 with the same body always results in the same state. POST is not idempotent — calling it twice might create two resources.

Method Registration

Methods are maintained in the IANA HTTP Method Registry. Servers that receive an unrecognized method SHOULD respond with 501 Not Implemented. If the method is recognized but not allowed for the target resource, the server responds with 405 Method Not Allowed and a required Allow header listing permitted methods.

Status Codes

Responses carry a three-digit status code grouped into five classes:

RangeClassMeaning
1xxInformationalRequest received, continuing process.
2xxSuccessfulRequest received, understood, and accepted.
3xxRedirectionFurther action needed to complete the request.
4xxClient ErrorRequest contains bad syntax or cannot be fulfilled.
5xxServer ErrorServer failed to fulfill a valid request.

1xx — Informational

CodeNameUsage
100ContinueServer has received the request headers and the client should proceed to send the body. Sent in response to Expect: 100-continue.
101Switching ProtocolsServer agrees to switch protocols via the Upgrade header (e.g., WebSocket).

2xx — Successful

CodeNameUsage
200OKStandard success response. Body contains the requested resource.
201CreatedResource was successfully created. Location header points to the new resource.
204No ContentSuccess, but no body to return (e.g., after a DELETE).
206Partial ContentRange request fulfilled. Used for resumable downloads.

3xx — Redirection

CodeNameUsage
301Moved PermanentlyResource has been permanently moved. Clients should update bookmarks.
302FoundTemporary redirect. Original URL should still be used in the future.
304Not ModifiedConditional request matched — the cached version is still valid. No body sent.
307Temporary RedirectLike 302, but the method and body MUST NOT change.
308Permanent RedirectLike 301, but the method and body MUST NOT change.

4xx — Client Error

CodeNameUsage
400Bad RequestMalformed syntax. The server MUST return this for specific violations (missing Host, duplicate Host, space before colon, etc.). This is what Http11Probe primarily tests.
401UnauthorizedAuthentication required. Must include WWW-Authenticate header.
403ForbiddenServer understood the request but refuses to fulfill it.
404Not FoundResource does not exist.
405Method Not AllowedMethod is recognized but not supported for this resource. Must include Allow header.
408Request TimeoutServer timed out waiting for the request.
411Length RequiredServer refuses the request without a Content-Length.
413Content Too LargeRequest body exceeds the server’s limits.
414URI Too LongRequest-target exceeds the server’s limits.
431Request Header Fields Too LargeHeaders are too large.

5xx — Server Error

CodeNameUsage
500Internal Server ErrorGeneric server failure.
501Not ImplementedServer does not recognize the request method.
502Bad GatewayThe server, acting as a gateway/proxy, received an invalid response from upstream.
503Service UnavailableServer is temporarily unable to handle the request (overloaded, maintenance).
504Gateway TimeoutThe server, acting as a gateway/proxy, did not receive a timely response from upstream.
505HTTP Version Not SupportedThe server does not support the HTTP version used in the request.