[WebUI|Py3] Refactor content_type check

Simplify getting content_type from request to prevent str/bytes mixup.
This commit is contained in:
Calum Lind 2018-10-09 14:47:29 +01:00
commit 6f06cd5ebc

View file

@ -194,10 +194,9 @@ class JSON(resource.Resource, component.Component):
Handler to take the json data as a string and pass it on to the Handler to take the json data as a string and pass it on to the
_handle_request method for further processing. _handle_request method for further processing.
""" """
if request.getHeader(b'content-type') != b'application/json': content_type = request.getHeader(b'content-type').decode()
message = 'Invalid JSON request content-type: %s' % request.getHeader( if content_type != 'application/json':
'content-type' message = 'Invalid JSON request content-type: %s' % content_type
)
raise JSONException(message) raise JSONException(message)
log.debug('json-request: %s', request.json) log.debug('json-request: %s', request.json)