diff options
author | Milo Casagrande <milo.casagrande@linaro.org> | 2014-04-03 16:34:18 +0200 |
---|---|---|
committer | Milo Casagrande <milo.casagrande@linaro.org> | 2014-04-03 16:34:18 +0200 |
commit | 7b49a6523b06d91b797de3a2f4f8d5c3fa0fb8e9 (patch) | |
tree | 5eaa5970c3799aaad782a0d3f1ce4af2b007415f /app/handlers/base.py | |
parent | 1d935924fe476ca88091be6eeeed00f82e355d70 (diff) |
Add check_content_type function.
Diffstat (limited to 'app/handlers/base.py')
-rw-r--r-- | app/handlers/base.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/app/handlers/base.py b/app/handlers/base.py index 95a9968..cbeb060 100644 --- a/app/handlers/base.py +++ b/app/handlers/base.py @@ -116,14 +116,14 @@ class BaseHandler(RequestHandler): :return A (int, str) tuple composed of the status code, and the message. """ - status, message = 200, self._get_status_message(200) - if isinstance(response, (types.DictionaryType, types.ListType)): status, message = 200, dumps(response) elif isinstance(response, types.IntType): status, message = response, self._get_status_message(response) elif isinstance(response, types.NoneType): status, message = 404, self._get_status_message(404) + else: + status, message = 200, self._get_status_message(200) self.set_status(status) self.write(dict(status=status, message=message)) @@ -150,10 +150,13 @@ class BaseHandler(RequestHandler): """ self._create_valid_response(result) + def _check_content_type(self): + if self.request.headers['Content-Type'] != self.accepted_content_type: + self.send_error(status_code=415) + @asynchronous def get(self, *args, **kwargs): if kwargs and kwargs['id']: - self.executor.submit( partial(find_one, self.collection, kwargs['id']) ).add_done_callback( @@ -182,7 +185,7 @@ class BaseHandler(RequestHandler): if status_message: self.set_status(status_code) - self.write(dict(code=status_code, message=status_message)) + self.write(dict(status=status_code, message=status_message)) self.finish() else: super(BaseHandler, self).write_error(status_code) |