I'm using python -m SimpleHTTPServer
to serve up a directory for local testing in a web browser. Some of the content includes large data files. I would like to be able to gzip them and have SimpleHTTPServer serve them with Content-Encoding: gzip.
Is there an easy way to do this?
This is an old question, but it still ranks #1 in Google for me, so I suppose a proper answer might be of use to someone beside me.
The solution turns out to be very simple. in the do_GET(), do_POST, etc, you only need to add the following:
strcontent being your actual content (as in HTML, javascript or other HTML resources) and the gzipencode:
As so many others, I've been using
python -m SimpleHTTPServer
for local testing as well. This is still the top result on google and while https://github.com/ksmith97/GzipSimpleHTTPServer is a nice solution, it enforces gzip even if not requested and there's no flag to enable/disable it.I decided to write a tiny cli tool that supports this. It's go, so the regular install procedure is simply:
go get github.com/rhardih/serve
If you already have
$GOPATH
added to$PATH
, that's all you need. Now you haveserve
as a command.https://github.com/rhardih/serve
Since this was the top google result I figured I would post my simple modification to the script that got gzip to work.
https://github.com/ksmith97/GzipSimpleHTTPServer
Building on @velis answer above, here is how I do it. gZipping small data is not worth the time and can increase its size. Tested with Dalvik client.
From looking at SimpleHTTPServer's documentation, there is no way. However, I recommend lighttpd with the mod_compress module.