Skip to content
This repository has been archived by the owner on Mar 28, 2019. It is now read-only.

Commit

Permalink
Service should only accept application/json content-types on POST/PUT…
Browse files Browse the repository at this point in the history
…/PATCH verbs.
  • Loading branch information
Rémy HUBSCHER committed Feb 25, 2016
1 parent 06aefb2 commit 486dbe1
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions cliquet/resource/viewset.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class ViewSet(object):

readonly_methods = ('GET', 'OPTIONS', 'HEAD')

content_types = ["application/json"]

service_arguments = {
'description': 'Collection of {resource_name}',
}
Expand All @@ -36,6 +38,18 @@ class ViewSet(object):
'permission': authorization.PRIVATE
}

default_post_arguments = {
"content_type": content_types,
}

default_put_arguments = {
"content_type": content_types,
}

default_patch_arguments = {
"content_type": content_types,
}

default_collection_arguments = {}
collection_get_arguments = {
'cors_headers': ('Next-Page', 'Total-Records', 'Last-Modified', 'ETag',
Expand Down Expand Up @@ -72,10 +86,14 @@ def get_view_arguments(self, endpoint_type, resource_cls, method):
'default_%s_arguments' % endpoint_type)
args.update(**default_arguments)

by_method = '%s_%s_arguments' % (endpoint_type, method.lower())
method_args = getattr(self, by_method, {})
by_http_verb = 'default_%s_arguments' % method.lower()
method_args = getattr(self, by_http_verb, {})
args.update(**method_args)

by_method = '%s_%s_arguments' % (endpoint_type, method.lower())
endpoint_args = getattr(self, by_method, {})
args.update(**endpoint_args)

args['schema'] = self.get_record_schema(resource_cls, method)

return args
Expand Down

0 comments on commit 486dbe1

Please sign in to comment.