HTTP Status Header Syntax

There are many ways to write the HTTP status header:

HTTP/1.1 404 Not Found Status: 404 Status: 404 Not Found 

but which is a semantically correct and spec-compatible way?

Edit: by status headers, I mean this , using a function like PHP header() .

+6
language-agnostic specifications
source share
4 answers

The closest I found for an answer is the โ€œQuick CGI Specification,โ€ which states to set status codes through status and location headers.

+1
source

Adding some information after some time, since I came across this question while researching something related.

I believe that the status header field was originally invented as part of the CGI specification, RFC 3875:

https://tools.ietf.org/html/rfc3875#section-6.3.3

Quote:

 The Status header field contains a 3-digit integer result code that indicates the level of success of the script attempt to handle the request. Status = "Status:" status-code SP reason-phrase NL status-code = "200" | "302" | "400" | "501" | extension-code extension-code = 3digit reason-phrase = *TEXT 

It allows a CGI script to return a status code to a web server, which overrides the default value specified in the HTTP status bar. Typically, the server buffers the result from the script and emits a new header for the client. This is a valid HTTP header that begins with the modified HTTP status bar and omits the "Status:" header field (plus some other conversions provided by the RFC).

So, all your examples are valid from a CGI script, but only the first one is really valid in the HTTP header. The last two are valid only from a CGI script (or, possibly, a FastCGI application).

A CGI script can also run in "incompatible header" (NPH) mode when it generates a full and valid HTTP header, which the web server transmits to the client verbatim. Thus, this should not include the Status header field:

Note that I am interested in what status should win if the NPH script is a little erroneous and emits a Status: header field, possibly in addition to the HTTP status bar. I cannot find any clear directions, so I suspect that it is left to implement what parses the output, whether it be a client or a server.

+4
source

Since http://tools.ietf.org/html/rfc2616#section-6 and more specifically http://tools.ietf.org/html/rfc2616#section-6.1 does not mention the use of "Status:" when specifying a status code and since the official heading list http://www.iana.org/assignments/message-headers/message-headers.xml does not mention โ€œStatusโ€, I would be inclined to believe that it should not be served as a heading.

+3
source

Many of them are pretty arbitrary strings, but there is a w3c specification for the most commonly used ones.

http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

0
source

All Articles