Shuai Li
Shuai Li

Reputation: 2766

Why is there a HTTP status message when there already is a HTTP status code?

An HTTP response may look like:

HTTP/1.1 200 OK

I think 200 is already tell client that it is OK, and OK in response can be omitted. So what is the approach that is existed?

Upvotes: 0

Views: 72

Answers (2)

cassiomolin
cassiomolin

Reputation: 130837

Such message is called reason phrase and, as mentioned in Julian Reschke's answer, it simply provides a textual description associated with the numeric status code and it should be ignored by the client. The reason phrase can even be empty.

While your question is about the HTTP/1.1 protocol, I would like to highlight that HTTP/2 responses don't carry any reason phrase. They carry only the status code, as defined in the RFC 7540:

For HTTP/2 responses, a single :status pseudo-header field is defined that carries the HTTP status code field. This pseudo-header field MUST be included in all responses; otherwise, the response is malformed.

HTTP/2 does not define a way to carry the version or reason phrase that is included in an HTTP/1.1 status line.

Upvotes: 1

Julian Reschke
Julian Reschke

Reputation: 41997

From https://greenbytes.de/tech/webdav/rfc7230.html#rfc.section.3.1.2:

The reason-phrase element exists for the sole purpose of providing a textual description associated with the numeric status code, mostly out of deference to earlier Internet application protocols that were more frequently used with interactive text clients. A client SHOULD ignore the reason-phrase content.

Upvotes: 1

Related Questions