A normal HTTP response looks like:
HTTP/1.0 200 OK
Is it OK to omit what the RFC calls the Reason-Phrase? Something like:
HTTP/1.0 200
The RFC says:
Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF
Reason-Phrase = *<TEXT, excluding CR, LF>
I understand this as:
- An empty string is OK for the Reason-Phrase
- But there should be a space after the Status-Code anyway
So the following would be valid:
HTTP-Version SP Status-Code SP CRLF
Do I understand the RFC correctly?
It looks that way, if you read the
*
as 'zero or more characters', like in regular expressions.It seems to have a slightly different meaning if you read the Notational Convention of the RFC:
So although it's not regex, the meaning is essentially the same. The asterix, not having a trailing number in this case, means that there can be "0 or more" "texts". Odd way to put it, but it seems you're right.
Strictly speaking, the space is mandatory, although I'd think a separator might be omitted if there's nothing to separate. It might kill clients that have a strict implementation, though, if they just split this string on the spaces and try to read the element in which the description should be. But then again, those clients should have used some defensive programming to catch that situation. ;)
The RFC does say that it can be any text, as long as it is a human readable description of the problem. This text is important, because the client may not understand the exact meaning of the status code, so it may need to display the text to the user. So even though you can omit it, I personally wouldn't.
The Reason-Phrase is indeed optional. In fact, HTTP/2 even dropped it entirely: