Skip to content
Myr

Don't rely on X-Requested-With for pretty print json response (#2193)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* Don't rely on X-Requested-With for pretty print json response * Fix test cases for pretty print json patch * Fix gramma error in docs for pretty print json config * Add changelog for JSONIFY_PRETTYPRINT_REGULAR

authored by Hsiaoming Yang · committed by GitHub · parent f5adb61 · Browse files · 6 files+11 added−8 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

6 files+11 added−8 removed

  • tests:+3 added−1 removed
  • other:+8 added−7 removed

6 files+11 added−8 removed

modified:docs/config.rst+3 added-5 removed
192 unmodified lines
193 behavior by changing this variable.194 This is not recommended but might give195 you a performance improvement on the196 cost of cacheability.197``JSONIFY_PRETTYPRINT_REGULAR`` If this is set to ``True`` (the default)198 jsonify responses will be pretty printed199 if they are not requested by an200 XMLHttpRequest object (controlled by201 the ``X-Requested-With`` header)197``JSONIFY_PRETTYPRINT_REGULAR`` If this is set to ``True`` or the Flask app198 is running in debug mode, jsonify responses199 will be pretty printed.200``JSONIFY_MIMETYPE`` MIME type used for jsonify responses.201``TEMPLATES_AUTO_RELOAD`` Whether to check for modifications of202 the template source and reload it203 automatically. By default the value is
276 unmodified lines
modified:flask/app.py+1 added-1 removed
312 unmodified lines
313 'EXPLAIN_TEMPLATE_LOADING': False,314 'PREFERRED_URL_SCHEME': 'http',315 'JSON_AS_ASCII': True,316 'JSON_SORT_KEYS': True,317 'JSONIFY_PRETTYPRINT_REGULAR': True,317 'JSONIFY_PRETTYPRINT_REGULAR': False,318 'JSONIFY_MIMETYPE': 'application/json',319 'TEMPLATES_AUTO_RELOAD': None,320 })321
1686 unmodified lines
modified:flask/json.py+1 added-1 removed
246 unmodified lines
247248 indent = None249 separators = (',', ':')250251 if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] and not request.is_xhr:251 if current_app.config['JSONIFY_PRETTYPRINT_REGULAR'] or current_app.debug:252 indent = 2253 separators = (', ', ': ')254255 if args and kwargs:
14 unmodified lines
modified:tests/test_basic.py+1 added-1 removed
993 unmodified lines
994 with app.test_request_context():995 rv = flask.make_response(996 flask.jsonify({'msg': 'W00t'}), 400)997 assert rv.status_code == 400998 assert rv.data == b'{\n "msg": "W00t"\n}\n'998 assert rv.data == b'{"msg":"W00t"}\n'999 assert rv.mimetype == 'application/json'10001001 rv = flask.make_response(1002 flask.Response(''), 400)
698 unmodified lines
modified:tests/test_helpers.py+2 added
287 unmodified lines
288289 def test_json_key_sorting(self):290 app = flask.Flask(__name__)291 app.testing = True292 app.debug = True293294 assert app.config['JSON_SORT_KEYS'] == True295 d = dict.fromkeys(range(20), 'foo')296297 @app.route('/')
592 unmodified lines
modified:CHANGES+3 added
9 unmodified lines
1011- Make `app.run()` into a noop if a Flask application is run from the12 development server on the command line. This avoids some behavior that13 was confusing to debug for newcomers.14- Change default configuration `JSONIFY_PRETTYPRINT_REGULAR=False`. jsonify()15 method returns compressed response by default, and pretty response in16 debug mode.1718Version 0.12.119--------------20
605 unmodified lines