diff --git a/voussoirkit/flasktools.py b/voussoirkit/flasktools.py index b532b11..f183082 100644 --- a/voussoirkit/flasktools.py +++ b/voussoirkit/flasktools.py @@ -1,4 +1,5 @@ import flask +import functools import gzip import io import werkzeug.wrappers @@ -12,6 +13,15 @@ GZIP_LEVEL = 3 REQUEST_TYPES = (flask.Request, werkzeug.wrappers.Request, werkzeug.local.LocalProxy) RESPONSE_TYPES = (flask.Response, werkzeug.wrappers.Response) +def ensure_response_type(function): + @functools.wraps(function) + def wrapped(*args, **kwargs): + response = function(*args, **kwargs) + if not isinstance(response, RESPONSE_TYPES): + response = flask.Response(response) + return response + return wrapped + def gzip_response(request, response): if response.direct_passthrough: return response