Closed mrx23dot closed 3 years ago
Honestly, I do not seen an easy way to implement this. We would need to rely on a global state that we could change from within the view, and that would affect programs that run things concurrently. Perhaps someone else has a better idea.
No worries, just close the ticket if there is no good solution. Cheers
What about manually compressing return payload?
def view
if 1:
return compress(payload_str)
else:
return payload_str
I think a simpler way would be to add the per-view decorator following some test, but this would not be "inside the view"
from flask import Flask
from flask_compress import Compress
app = Flask(__name__)
app.config["COMPRESS_REGISTER"] = False # disable default compression of all eligible requests
compress = Compress()
compress.init_app(app)
@app.route("/test")
def view():
pass
if 1:
view = compress.compressed()(view)
Is there an easy way to conditional disable compression inside view?
(so I could serve local clients with uncompressed, and remote ones with compress data on the same view)
Like: