diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-08-19 16:08:21 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-08-19 16:08:21 +0000 |
commit | 604b76e56ed92813c0e06f8ece72bc136865f927 (patch) | |
tree | 80f0bf0d0f91d124466115069bc67776267446aa | |
parent | d8ddf8e4e8d461de4842dd6392620efe332ee141 (diff) | |
download | apifw-604b76e56ed92813c0e06f8ece72bc136865f927.tar.gz |
Fix: test for whehter request has a JSON body
-rw-r--r-- | apifw/bottleapp.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/apifw/bottleapp.py b/apifw/bottleapp.py index 97987c6..04cf74a 100644 --- a/apifw/bottleapp.py +++ b/apifw/bottleapp.py @@ -203,13 +203,16 @@ class BottleApplication: return wrapper def _get_request_body(self): + json_type = 'application/json' content_type = bottle.request.get_header('Content-Type') raw_body = bottle.request.body.read() - if raw_body != 'application/json': + if content_type != json_type: return content_type, raw_body try: - return content_type, json.loads(raw_body) + text_body = raw_body.decode('UTF-8') + parsed = json.loads(text_body) + return content_type, parsed except json.decoder.JSONDecodeError as e: raise bottle.HTTPError(status=apifw.HTTP_BAD_REQUEST, body=str(e)) |