Improve compression by removing whitespace from separators when using jsonify() and JSONIFY_PRETTYPRINT_REGULAR is False.

Commit includes Changelog entry and two new tests in test_basic.py.
This commit is contained in:
Gilman Callsen 2014-10-13 16:30:45 -04:00 committed by Markus Unterwaditzer
parent 050a659c2f
commit d425279650
3 changed files with 39 additions and 1 deletions

View file

@ -227,15 +227,22 @@ def jsonify(*args, **kwargs):
This function's response will be pretty printed if it was not requested
with ``X-Requested-With: XMLHttpRequest`` to simplify debugging unless
the ``JSONIFY_PRETTYPRINT_REGULAR`` config parameter is set to false.
Compressed (not pretty) formatting currently means no indents and no
spaces after separators.
.. versionadded:: 0.2
"""
indent = None
separators = (',', ':')
if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] \
and not request.is_xhr:
indent = 2
separators = (', ', ': ')
return current_app.response_class(dumps(dict(*args, **kwargs),
indent=indent),
indent=indent, separators=separators),
mimetype='application/json')