HTTP response (source code)

= HTTP response
{c}

An <HTTP response> is a message returned in response to an <HTTP request>, carrying an <HTTP status code>, associated <HTTP header fields> and any permitted content. An exchange can include informational responses before its final response.<HTTP Semantics>[§§6 and 15, messages and status classes]{ref}

For an invented plain-text resource, a successful `GET` can return status `200`, `Content-Type: text/plain; charset=utf-8` and the content `blue`. These four letters occupy four bytes in <UTF-8>, so a corresponding content length is four. The <HTTP representation>'s data, its <media type> and the status describing this exchange have different roles.

A response need not contain a representation body. A successful `PUT` can return `204` without response content, and a `HEAD` response carries no content even when the corresponding `GET` would retrieve data. Interpreting a response therefore requires the request method as well as the status code.<HTTP Semantics>[§9.3.2, HEAD; §15.3.5, 204]{ref}

In <HTTP 1.1>, `HTTP/1.1 200 OK` is a possible status line, followed by field lines, an empty line and any message body allowed by the framing rules. This spelling is one version's concrete syntax for the broader response abstraction.<HTTP 1.1 (RFC 9112)>[§§2.1, 4 and 6, message format, status line and body]{ref}

The received content can change between requests while the resource identifier stays the same. Conversely, the same content can accompany different exchange metadata. Inspect status, fields and content together instead of treating any one of them as the entire response or as a guarantee of an application-specific result.