HTTP response setStatus has API problem with non-standard/proposed status codes
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 3 |
Fix Released
|
Undecided
|
Shane Hathaway |
Bug Description
The setStatus API on the HTTP response (zope.publisher
setStatus is understandably unaware of the '209' status. However, its approach has two issues. First, it silently ignores the requested, unknown status, switching to 500, not even logging a problem (see below). Second, it gives no approved API method to teach the method a new status.
def setStatus(self, status, reason=None):
'See IHTTPResponse'
if status is None:
status = 200
else:
if type(status) in StringTypes:
status = status_
if reason is None:
reason = status_
I propose two changes.
First, "status = status_
Second, the module should grow an API to add an approved status. "addStatus(code, reason)" looks reasonable. Then I suppose it would continue to do the DWIMmy things that status_codes generation does now. This function should be part of an interface that the zope.publisher.http module provides.
If I don't hear any objections, I volunteer to make these changes.
Changed in zope3: | |
status: | Fix Committed → Fix Released |
I literally *just* ran into this same exact problem. In our case, we want to use non-standard status codes that are outside of the http spec. Although the reason we specify gets used, the code is always set to 500.
The fix is simple, just change the following:
else:
status = status.lower() codes.get( status, 500)
self._ status = status
if type(status) in StringTypes:
status = status_
to (note indentation)
else:
status = status.lower()
status = status_ codes.get( status, 500)
self._ status = status
if type(status) in StringTypes:
This is a major problem for me right now, so I'm going to fix it immediately.