1. Brodie Rao
  2. django-piston-oauth2


Brodie Rao  committed 6f24ec6

Support POSTing form-encoded data even with incorrect Content-Types

  • Participants
  • Parent commits d34d1fc
  • Branches default

Comments (0)

Files changed (1)

File piston/resource.py

View file
  • Ignore whitespace
 from django.conf import settings
 from django.core.mail import send_mail, EmailMessage
 from django.db.models.query import QuerySet
-from django.http import Http404
+from django.http import Http404, QueryDict
 from emitters import Emitter
 from handler import typemapper
             # We treat HEADs as GETs and leave it up to Django to drop the body.
             rm = 'GET'
+        # If this is a POST without a valid Content-Type, try to parse it
+        # as if it were form encoded anyway (to match Django's old behavior).
+        if rm in ('POST', 'PUT'):
+            if (not request.POST and
+                not request.META.get('CONTENT_TYPE', '').startswith(
+                    ('multipart/form-data',
+                     'application/x-www-form-urlencoded'))):
+                request.POST = QueryDict(request.body,
+                                         encoding=request.encoding)
         # Django's internal mechanism doesn't pick up
         # PUT request, so we trick it a little here.
         if rm == "PUT":