Add ensure_response_type decorator.
So that all further decorators or response-processors know they have a Response object.
This commit is contained in:
parent
45da148493
commit
ee8c4b7fd8
1 changed files with 10 additions and 0 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue