New in 7.3: Default HTTP response status messages

Among the many new features contained in Racket version 7.3, the web server got an update that makes things a bit more convenient for web developers. It’s a minor change, but it may make your web life in Racket a bit more comfortable.

It used to be that when you used the standard HTTP response constructors, a default value—Okay—was used for the status message part (the bit that comes after the status code), unless you provided something else. That meant that Okay was used for all responses, not just for responses with code 200.

That 404 response you created? It may well have started with 404 Okay, unless you took the trouble to supply something else (Not Found would be a sensible value).

One can debate whether status messages are needed at all, given that one usually looks to the status code, headers, and body when processing HTTP responses. Indeed, one may ask: why include data (the status message) that is a function of another piece of the response (the status code)?

In any case, it doesn’t feel right to reply Okay to everything, even if that practice isn’t really wrong.

Starting in Racket 7.3, we’re in a better place: if you use

pass in #f for the status message bit (#:message for response/xexpr, the second argument of response/full, and the #:message keyword argument for response/output) to have the message inferred from the status code. Thus, if the status code is 404 and you pass in #f, the status message will be Not Found. And so on for a bunch of standard status codes.

Which ones are supported? These (coming from RFC 7231 and RFC 7235):

Code Message
100 Continue
101 Switching Protocols
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other
305 Use Proxy
307 Temporary Redirect
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
413 Payload Too Large
414 URI Too Long
415 Unsupported Media Type
417 Expectation Failed
426 Upgrade Required
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported

If you omit the status message (or pass in #f), and if the status code is not in the above list, the fallback status message OK will be used.

As before, you can supply your own status messages, if you wish. respond/full & friends will pass that along when they ultimately make a response.