Comprehensive list of HTTP status codes that don't include a response body
Asked Answered
M

2

21

I have discovered that some HTTP status codes, like 304, contain no message body and are terminated by CRLF.

Is there a comprehensive list of such codes? So far I have got: 100-199, 204, and 304. Are there any others?

I am concerned with message delimiting with persistent connections, i.e., where does one HTTP message stop and the next begin?

Misfortune answered 25/12, 2011 at 7:47 Comment(6)
this is a list of HTTP status codes (en.wikipedia.org/wiki/List_of_HTTP_status_codes)... BEWARE that even codes which return a response body might in some situations behave differently and come back with no response body (server bug, network porblem, whatever)... I would strongly recommend to not rely on the pure standard BUT to handle whatever you receive accordingly and gracefully - at least in manner that your code doesn't just die or produce incorrect results...Bulganin
@Bulganin what I am concerned about is ONLY HTTP Message Delimiting. i.e. Where does one message stop and the next one begin?Misfortune
did you read my complete comment ?Bulganin
The answer: 4.4 section of the HTTP standard, answers my question.Misfortune
The question is unclear: is this about error codes that MUST NOT include a response body, or about those which MAY NOT (in RFC jargon)? Further, how is this related to the "concern" with "message delimiting"? I.e., what specific problem would be solved by knowing the answer?Winson
@KarlKnechtel OP doesn't know that there's a difference, clearly. That's been appropriately addressed in both answers. OP also doesn't need to show what downstream problems may be solved by this. This (empty HTTPS status codes) is a thing that can be so, and OP wants to know the bounds of it. They don't need to explain other things for the question to be valid.Sanjiv
W
23

A body is optional for all the 4xx error codes:

Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation, and whether it is a temporary or permanent condition.

Same for the 5xx:

Except when responding to a HEAD request, the server SHOULD include an entity containing an explanation of the error situation...

(SHOULD means that really, they should, but it's not a MUST.)

The 1xx messages don't contain a body as far as I can tell. 201 (in addition to 204 and 205) doesn't have to have a body. The 3xx are a mixed bag, but a body is optional for a lot of them.

Source: HTTP/1.1: Status Code definitions.

The rules for message length information are described in HTTP Message - 4.4 Message Length. It's not exactly trivial.

Weber answered 25/12, 2011 at 7:57 Comment(1)
if they include no body, do they include a Content-Length: 0 header? How do I delimit these with persistent connections?Misfortune
T
4

Every single status can optionally have no content. However there are some statuses that MUST not contain content:

This is the full list for RFC 9110, which is the current HTTP Semantics spec at the time of this writing. The list in Mat's answer is incomplete.

Transposal answered 31/3 at 3:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.