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)

django-webdav-reason-phrases.patch (1.1 KB ) - added by Vasiliy Faronov 13 years ago.
Patch to add RFC 4918 reason phrases
django-all-reason-phrases.patch (1.4 KB ) - added by Vasiliy Faronov 13 years ago.
Patch to add all IANA registered reason phrases

Download all attachments as: .zip

Change History (7)

by Vasiliy Faronov, 13 years ago

Patch to add RFC 4918 reason phrases

comment:1 by Aymeric Augustin, 13 years ago

Triage Stage: UnreviewedDesign decision needed
Type: UncategorizedCleanup/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:

  1. including only HTTP codes (RFC 2616),
  2. including HTTP + WebDAV codes (RFC 2616 + 4918),
  3. 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 Russell Keith-Magee, 13 years ago

Patch needs improvement: set
Triage Stage: Design decision neededAccepted

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 Vasiliy Faronov, 13 years ago

Patch to add all IANA registered reason phrases

comment:3 by Vasiliy Faronov, 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 Russell Keith-Magee, 13 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady 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.

comment:5 by Jacob, 13 years ago

Resolution: fixed
Status: newclosed

In [16732]:

Fixed #16746 - added more HTTP code/string mappings.

This moves the arbitrary line on which HTTP codes to include away from
RFC 2616 and to the IANA assignments, thus picking up WebDAV and a couple
others.

Thanks to vfaronov for the patch.

Note: See TracTickets for help on using tickets.
Back to Top