forked from orbit-oss/flask
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:
parent
050a659c2f
commit
d425279650
3 changed files with 39 additions and 1 deletions
|
|
@ -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')
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue