Opened 12 years ago
Closed 12 years ago
#18678 closed Bug (fixed)
HTTPResponse subclasses don't accept base class parameters
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | HTTP handling | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
I would like to pass content_type
when creating a new HttpResponseNotAllowed
object. Unfortunately, it does not accept parameters from its base class, HttpResponse
. Doing the following results in an error:
return HttpResponseNotAllowed(content_type="application/json", permitted_methods=['POST'], )
There is a simple fix to this. See my patch below. This patch should be applied to other HttpResponse
sub-classes as well. Namely, HttpResponseRedirect
and HttpResponsePermanentRedirect
.
class HttpResponseNotAllowed(HttpResponse): status_code = 405 def __init__(self, permitted_methods, *args, **kwargs): super(HttpResponseNotAllowed, self).__init__(*args, **kwargs) self['Allow'] = ', '.join(permitted_methods)
Attachments (1)
Change History (6)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Version: | 1.3 → master |
I also think that we should allow HttpResponse standard parameters for all subclasses. I don't see anything in the HTTP spec that prevents a response to have attached content (with content-type).
comment:3 by , 12 years ago
Has patch: | set |
---|
comment:4 by , 12 years ago
Sorry, I'm a bit late. My use case is a proprietary RESTful client that will reject all communication that is not of a specific content-type. Even if the status code is correct.
comment:5 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Can you provide more detail about your use case - while I can't find anything in a quick review of the spec that prohibits setting a content-type for a 405 response, it is hard to imagine a client that would do something specific with it.
If this is in fact something that should be supported - it should be supported for most (all?) included subclasses of HttpResponse.