From 663e65795adfb2f6745513e34936b2ef746dcdc5 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Fri, 4 Jun 2021 21:48:04 -0700 Subject: [PATCH] Add flasktools.make_json_response. --- voussoirkit/flasktools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/voussoirkit/flasktools.py b/voussoirkit/flasktools.py index f183082..ba06fc8 100644 --- a/voussoirkit/flasktools.py +++ b/voussoirkit/flasktools.py @@ -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