diff --git a/hug/api.py b/hug/api.py index 1959ac8d..3955fa11 100644 --- a/hug/api.py +++ b/hug/api.py @@ -307,7 +307,7 @@ def handle_404(request, response, *args, **kwargs): prefix=url_prefix) response.data = hug.output_format.json(to_return, indent=4, separators=(',', ': ')) response.status = falcon.HTTP_NOT_FOUND - response.content_type = 'application/json' + response.content_type = 'application/json; charset=utf-8' handle_404.interface = True return handle_404 diff --git a/hug/output_format.py b/hug/output_format.py index 5482428a..a9c663da 100644 --- a/hug/output_format.py +++ b/hug/output_format.py @@ -105,7 +105,7 @@ def numpy_floatable(item): return float(item) -@content_type('application/json') +@content_type('application/json; charset=utf-8') def json(content, request=None, response=None, ensure_ascii=False, **kwargs): """JSON (Javascript Serialized Object Notation)""" if hasattr(content, 'read'): @@ -141,7 +141,7 @@ def output_content(content, response, **kwargs): return wrapper -@content_type('text/plain') +@content_type('text/plain; charset=utf-8') def text(content, **kwargs): """Free form UTF-8 text""" if hasattr(content, 'read'): @@ -150,7 +150,7 @@ def text(content, **kwargs): return str(content).encode('utf8') -@content_type('text/html') +@content_type('text/html; charset=utf-8') def html(content, **kwargs): """HTML (Hypertext Markup Language)""" if hasattr(content, 'read'): @@ -178,13 +178,13 @@ def _camelcase(content): return content -@content_type('application/json') +@content_type('application/json; charset=utf-8') def json_camelcase(content, **kwargs): """JSON (Javascript Serialized Object Notation) with all keys camelCased""" return json(_camelcase(content), **kwargs) -@content_type('application/json') +@content_type('application/json; charset=utf-8') def pretty_json(content, **kwargs): """JSON (Javascript Serialized Object Notion) pretty printed and indented""" return json(content, indent=4, separators=(',', ': '), **kwargs) diff --git a/hug/test.py b/hug/test.py index d231d484..3536c800 100644 --- a/hug/test.py +++ b/hug/test.py @@ -64,7 +64,7 @@ def call(method, api_or_module, url, body='', headers=None, params=None, query_s except (UnicodeDecodeError, AttributeError): response.data = result[0] response.content_type = response.headers_dict['content-type'] - if response.content_type == 'application/json': + if 'application/json' in response.content_type: response.data = json.loads(response.data) return response