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
#f for the status message bit (
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):
|405||Method Not Allowed|
|407||Proxy Authentication Required|
|413||Payload Too Large|
|414||URI Too Long|
|415||Unsupported Media Type|
|500||Internal Server Error|
|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.