Code

Opened 3 years ago

Closed 3 years ago

#16746 closed Cleanup/optimization (fixed)

Include default reason phrases for WebDAV

Reported by: vfaronov Owned by: nobody
Component: HTTP handling Version: master
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 vfaronov 3 years ago.
Patch to add RFC 4918 reason phrases
django-all-reason-phrases.patch (1.4 KB) - added by vfaronov 3 years ago.
Patch to add all IANA registered reason phrases

Download all attachments as: .zip

Change History (7)

Changed 3 years ago by vfaronov

Patch to add RFC 4918 reason phrases

comment:1 Changed 3 years ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Design decision needed
  • Type changed from Uncategorized to 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:

  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 Changed 3 years ago by russellm

  • Patch needs improvement set
  • Triage Stage changed from Design decision needed to 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)

Changed 3 years ago by vfaronov

Patch to add all IANA registered reason phrases

comment:3 Changed 3 years ago by vfaronov

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 Changed 3 years ago by russellm

  • Patch needs improvement unset
  • Triage Stage changed from Accepted to 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.

comment:5 Changed 3 years ago by jacob

  • Resolution set to fixed
  • Status changed from new to closed

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.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.