How to set content-encoding parameters


I’m trying to test different types of compression on some of my webpages but when I try to set the set the headers to either gzip or br I get “(failed)net::ERR_CONTENT_DECODING_FAILED” in the status. However, in the response I am getting a status 200 with the correct content-encoding applied but with a blank page.

I am currently testing locally, but is this something I would need to setup with whatever I’m using to serve the pages? i.e. Apache?

Here is the snippet of code:

async def gzip_page(request):
return response.json(
    {'message': 'OK'},
    headers={'Content-Encoding': 'gzip'},
    content_type='text/plain; charset=utf-8'

The problem is you are still just sending JSON data, but telling the browser it is gzipped. So, there is a conflict. You will need to gzip the file, and then serve that.


Awesome, thanks for the response. Would that be the same with brotli as well?

EDIT: Sorted it out, thanks for your help! :slight_smile: