Issue #182 resolved

Django-piston ignores "Accept" header

fsang
created an issue

In my setup django-piston always returns json, without honoring the "Content-Type" or "Accept" header.

Example: {{{ GET /api/user/1/ HTTP/1.1 Host: test.local:2020 Content-Type: text/xml Accept: text/xml

HTTP/1.0 200 OK Date: Tue, 22 Mar 2011 08:47:33 GMT Server: WSGIServer/0.1 Python/2.4.3 Vary: Authorization Content-Type: application/json; charset=utf-8 }}}

The handler is configured to support JSON and XML: {{{

!python

class UserHandler(BaseHandler): allowed_methods = ('GET',)

@require_mime('xml', 'json',)
def read(self, request, user):

}}}

Comments (5)

  1. Anonymous

    Yes, please! Support for Accepts headers and rel attributes would be the last steps needed to allow piston to actually support REST!

  2. simongee

    First off, thank you for adding in Accept support.

    However, would it be possible to change the following in resource.py around line 72

    if 'format' in request.GET:

    return request.GET.get('format')

    to

    if 'format' in request.REQUEST:

    return request.REQUEST.get('format')

    That would make our API wrappers a wee bit cleaner, as we wouldn't have to include the ?format=xml in the URL and can just send it along as a regular (POST, GET, DELETE, ..) parameter.

    WDYT?

  3. Log in to comment