This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import gzip | |
from io import BytesIO as IO | |
def send_response(request, response): | |
accept_encoding = request.headers.get("Accept-Encoding", "") or request.headers.get("accept-encoding", "") | |
if ("gzip" not in accept_encoding.lower()) or (response.status < 200 or response.status >= 300 or "Content-Encoding" in response.headers): | |
return response |