Skip to content
Myr

Add JSONIFY_MIMETYPE configuration variable (#1728)

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

Allow jsonify responses' mimetype to be configured

authored by Steven Loria · committed by David Lord · parent 0690ce1 · Browse files · 5 files+16 added−1 removed
This commit

State

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

Diff stats

5 files+16 added−1 removed

  • tests:+12 added−0 removed
  • other:+4 added−1 removed

5 files+16 added−1 removed

modified:docs/config.rst+1 added
181 unmodified lines
182 jsonify responses will be pretty printed183 if they are not requested by an184 XMLHttpRequest object (controlled by185 the ``X-Requested-With`` header)186``JSONIFY_MIMETYPE`` MIME type used for jsonify responses.187``TEMPLATES_AUTO_RELOAD`` Whether to check for modifications of188 the template source and reload it189 automatically. By default the value is190 ``None`` which means that Flask checks
274 unmodified lines
modified:flask/app.py+1 added
313 unmodified lines
314 'PREFERRED_URL_SCHEME': 'http',315 'JSON_AS_ASCII': True,316 'JSON_SORT_KEYS': True,317 'JSONIFY_PRETTYPRINT_REGULAR': True,318 'JSONIFY_MIMETYPE': 'application/json',319 'TEMPLATES_AUTO_RELOAD': None,320 })321322 #: The rule object to use for URL rules created. This is used by
1668 unmodified lines
modified:flask/json.py+1 added-1 removed
262 unmodified lines
263 data = args or kwargs264265 return current_app.response_class(266 (dumps(data, indent=indent, separators=separators), '\n'),267 mimetype='application/json'267 mimetype=current_app.config['JSONIFY_MIMETYPE']268 )269270271def tojson_filter(obj, **kwargs):
1 unmodified line
modified:tests/test_basic.py+12 added
1017 unmodified lines
1018 flask.jsonify(compressed_msg), 200)1019 assert rv.data == pretty_response102010211022def test_jsonify_mimetype():1023 app = flask.Flask(__name__)1024 app.config.update({"JSONIFY_MIMETYPE": 'application/vnd.api+json'})1025 with app.test_request_context():1026 msg = {1027 "msg": {"submsg": "W00t"},1028 }1029 rv = flask.make_response(1030 flask.jsonify(msg), 200)1031 assert rv.mimetype == 'application/vnd.api+json'103210331034def test_url_generation():1035 app = flask.Flask(__name__)10361037 @app.route('/hello/<name>', methods=['POST'])
593 unmodified lines
modified:CHANGES+1 added
74 unmodified lines
75 (pull request ``#1515``).76- ``flask.ext`` is now deprecated (pull request ``#1484``).77- ``send_from_directory`` now raises BadRequest if the filename is invalid on78 the server OS (pull request ``#1763``).79- Added the ``JSONIFY_MIMETYPE`` configuration variable (pull request ``#1728``).8081Version 0.10.282--------------83
480 unmodified lines