Compress content


#1

Sorry to bother - but I tried a few different ways and I can not get this to work right. I am trying to build out a way to compress the data to response using gzip, but the data that the client gets is compress, but does not uncompressed when viewing the data. My understanding is that chrome/ie should be able to see this and uncompressed content data to show the website, but all I see if the compress content version. How would I go about this to make it work?

My end goal here is to improve on website bandwidth just a bit by compress the returning data, remove white-space, convert some image files into more static type information files, file caching, and etc. Not sure if there are any projects going on to maybe do such a thing already?

Return the request information

if "html" in file["content-type"]:
    gzip_buffer = io.BytesIO()
    with gzip.GzipFile(mode='wb', compresslevel=8, fileobj=gzip_buffer) as gzip_file:
        gzip_file.write(temp)
    temp = gzip_buffer.getvalue()
return http.HTTPResponse.make(200, temp, {"Content-Type": file["content-type"], 'Content-Encoding': 'gzip', "Cache-Control": "private", "Vary": 'Accept-Encoding'})