Browse Source

fix(api): accept application/json only, fixes #103

Peter Thomassen 6 years ago
parent
commit
6895071a18
2 changed files with 6 additions and 0 deletions
  1. 4 0
      api/api/settings.py
  2. 2 0
      api/desecapi/views.py

+ 4 - 0
api/api/settings.py

@@ -105,6 +105,10 @@ REST_FRAMEWORK = {
     'DEFAULT_AUTHENTICATION_CLASSES': (
         'desecapi.authentication.TokenAuthentication',
     ),
+    'DEFAULT_PARSER_CLASSES': (
+        'rest_framework.parsers.JSONParser',
+    ),
+    'TEST_REQUEST_DEFAULT_FORMAT': 'json',
 }
 
 # user management configuration

+ 2 - 0
api/desecapi/views.py

@@ -213,6 +213,8 @@ class RRsetDetail(generics.RetrieveUpdateDestroyAPIView):
             return self.delete(request, *args, **kwargs)
 
         for k in ('type', 'subname'):
+            # This works because we exclusively use JSONParser which causes request.data to be
+            # a dict (and not an immutable QueryDict, as is the case for other parsers)
             request.data[k] = request.data.pop(k, self.kwargs[k])
 
         try: