Add flasktools.make_json_response.

This commit is contained in:
voussoir 2021-06-04 21:48:04 -07:00
parent ee8c4b7fd8
commit 663e65795a
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -2,6 +2,7 @@ import flask
import functools
import gzip
import io
import json
import werkzeug.wrappers
from voussoirkit import bytestring
@ -59,3 +60,9 @@ def gzip_response(request, response):
response.headers['Content-Length'] = len(response.get_data())
return response
def make_json_response(j, *args, **kwargs):
dumped = json.dumps(j)
response = flask.Response(dumped, *args, **kwargs)
response.headers['Content-Type'] = 'application/json;charset=utf-8'
return response