Allow non-standard http status codes to be used
See original GitHub issueKoa throws when a status code not defined in the statuses
package is used in response:
https://github.com/koajs/koa/blob/78832ff6c63fdd93ad9a49f31ba2edd8cbe8adee/lib/response.js#L84
However, the HTTP RFC does not prevent custom status codes to be used: http://greenbytes.de/tech/webdav/draft-ietf-httpbis-p2-semantics-25.html#rfc.section.6.p.2
I can understand why status code validation might be useful for people just starting with http protocols, but for people who actually need to use custom codes, this is very limiting.
Proposal
There are several options that the Koa team could choose to remediate the problem:
- Do not throw an error and just emit a warning
- Keep throwing but add a configuration flag to disable the check (ie.
koa.validateStatus = false
) - Allow adding custom http status codes to Koa so that it accepts them (ie.
koa.AddStatus(440, 'Invalid Chicken')
)
I personally like the second and third approach. Currently the third approach is possible, albeit in a hacky way:
import statuses from 'statuses'
// Add a hypothetical "invalid chicken" response code
statuses[440] = 'Invalid chicken'
statuses.codes.push(440)
statuses['Invalid chicken'] = 440
Issue Analytics
- State:
- Created 6 years ago
- Reactions:12
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Non-standard HTTP response codes: recommended client ...
How should a http client (web-browser or other app) process non-standard HTTP response codes like 190, 290, 320, 420, 540.
Read more >HTTP response status codes - MDN Web Docs - Mozilla
HTTP response status codes indicate whether a specific HTTP request has been successfully completed. Responses are grouped in five classes:
Read more >Understanding HTTPS Status Codes + a Complete List
Check out this article to learn about HTTP Status Codes: 1xx Informational; 2xx Success; 3xx Redirection; 4xx Client Error; 5xx Server ...
Read more >HTTP Status Codes: All 63 explained - including FAQ & Video
The differences in classes are indicated through the first digit of the error code, for example: just like a 404, any other 4xx...
Read more >HTTP Response Codes | What is HTTP Status Error Codes
This code should be used when a resource has been intentionally removed and the resource should not be purged. When a 410 status...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Last option, which I would prefer, is not to expose an API for handling statuses but rather to expose the validation fn, which can be overloaded/replaced as needed.
What about just validating that the status code is a number as per the HTTP spec?