0
BaseHTTPServer serving Gziped content
source link: https://fann.im/blog/2010/07/12/basehttpserver-serving-gziped-content/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
BaseHTTPServer serving Gziped content
Jul 12, 2010
BaseHTTPServer 使用 gzip 压缩处理 html/xml 文档。
import cStringIO, gzip
zbuf = cStringIO.StringIO()
zfile = gzip.GzipFile(mode='wb', compresslevel=6, fileobj=zbuf)
zfile.write(xmlstring)
zfile.close()
compressed_content = zbuf.getvalue()
self.send_response(200)
self.send_header("Content-Type", "text/xml")
self.send_header("Content-Length", str(len(compressed_content)))
self.send_header("Content-Encoding","gzip")
self.end_headers()
self.wfile.write(compressed_content)
self.wfile.flush()
Was this page helpful?
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK