Opened 13 years ago
Closed 13 years ago
#16746 closed Cleanup/optimization (fixed)
Include default reason phrases for WebDAV
Reported by: | Vasiliy Faronov | Owned by: | nobody |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Ready for checkin | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Django ships a mapping of HTTP status codes to reason phrases in django/core/handlers/wsgi.py (they are not overridable; see ticket:12747). It covers codes defined in HTTP/1.1 (RFC 2616). I would like to extend this list with codes from the WebDAV protocol (RFC 4918). Some of these codes (such as 422) are useful when building HTTP APIs, and seeing a reason phrase in a response instead of "UNKNOWN STATUS CODE" aids development. WebDAV is a well-established protocol, and RFC 4918 is Proposed Standard at IETF.
Attachments (2)
Change History (7)
by , 13 years ago
Attachment: | django-webdav-reason-phrases.patch added |
---|
comment:1 by , 13 years ago
Triage Stage: | Unreviewed → Design decision needed |
---|---|
Type: | Uncategorized → Cleanup/optimization |
There are even more status codes defined by other RFCs, like "425 Unordered Collection". There's a list on Wikipedia.
In my opinion, someone must make an arbitrary choice between:
- including only HTTP codes (RFC 2616),
- including HTTP + WebDAV codes (RFC 2616 + 4918),
- including every non-esoteric HTTP code.
I don't have any strong arguments in favor or against any of these options.
Until this is resolved, one way or another, you can import STATUS_CODE_TEXT in your code (for instance at the end of your settings file) and modify it:
from django.core.handlers.wsgi import STATUS_CODE_TEXT STATUS_CODE_TEXT.update({200: "Look ma!", 425: "Unordered Collection"})
After launching runserver
:
% curl -D - http://localhost:8000/ ~ HTTP/1.0 200 Look ma! ...
comment:2 by , 13 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Design decision needed → Accepted |
I think it certainly makes sense to include WebDAV codes and anything else that has formal RFC ratification (with the possible exception of HTTP 418 :-)
I'm less convinced of the importance of implementing other "nonstandard" codes, like nginX extensions (like 444 and 499) -- mostly because we have no guarantee that they won't overlap. The Wikipedia page doesn't seem to suggest that this is happening so far, but I'd rather not endorse informal extension codes unless there's evidence that they're in wide use (as in the case of 509)
by , 13 years ago
Attachment: | django-all-reason-phrases.patch added |
---|
Patch to add all IANA registered reason phrases
comment:3 by , 13 years ago
I have discovered this registry: http://www.iana.org/assignments/http-status-codes
The new patch includes all codes defined there (with the exception of the reserved 425).
By the way, I'm not sure why Django's phrases are all uppercase, while the more popular practice is title capitalization. But this is really cosmetic, so I haven't touched it.
comment:4 by , 13 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
Patch looks good to me, and pointing at an IANA list gives much better political cover for why a particular code list has been used.
I'm accepting this with out a test because it's a extensions to a list of lookup values, so there isn't any extra logic to test here.
Patch to add RFC 4918 reason phrases