0

RFC 2616 section 6.1.1 specifies that "HTTP status codes are extensible":

HTTP status codes are extensible. HTTP applications are not required to understand the meaning of all registered status codes, though such understanding is obviously desirable.

A common example is Twitter's 420 Enhance Your Calm.

I want to respond with custom codes in a Rack application. I'm able to use custom codes in a super-straightforward way:

app = proc do |env|
  ['299', {}, ['Hey there custom status codes!']]
end

run app

The server responds correctly with:

HTTP/1.1 299
Connection: Keep-Alive
...

What I want to do though is define custom codes and associated custom messages. I've searched Rack documentation and googled for a while but didn't come to any conclusive answer.

Community
  • 1
  • 1
whatyouhide
  • 15,897
  • 9
  • 57
  • 71

1 Answers1

3

(1) Do not use custom status codes unless the intent is to actually document and register them.

(2) The status message is for debugging only, and you can't rely on it not being mangled by intermediaries or software libraries. Also, it's gone in HTTP/2.

(3) If you need additional information in your response, consider putting it into the message body.

(4) For more information, see RFC 7231, not RFC 2616.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98
  • Thanks. For (1), I'm writing a university research essay, so it's for demonstration purposes only. I know (2) for the same reasons. I don't need to implement anything with it (3). Anyways, I though RFC 7231 was still a proposed standard since it's pretty recent (June 2014); is it the to-go standard? – whatyouhide Jul 26 '14 at 11:51
  • RFC 7231 is (part of) the current HTTP/1.1 standard. RFC 2616 has been obsoleted. – Julian Reschke Jul 26 '14 at 18:41