瓶文档说:
..。根据瓶子项目的建议,Gzip压缩最好由运行在WSGI服务器上的瓶子来处理。像cherrypy这样的WSGI服务器提供了一个
GzipFilter中间件,可以用来实现这一点。
目前,我正在运行我的瓶子服务器:
app.run(host='...', port=8080, server='cherrypy')我如何告诉cherrypy使用gzip压缩?
我可以获得像这样的cherrypy服务器对象,但我仍然无法找到如何启用gzip:
class CherryPyGzip(ServerAdapter):
def run(self, handler):
from cherrypy import wsgiserver
server = wsgiserver.CherryPyWSGIServer((self.host, self.port), handler)
# enable gzip here somehow?
try:
server.start()
finally:
server.stop()
app.run(host='...', port=8080, server=CherryPyGzip)发布于 2014-04-07 23:00:42
CherryPy有Gzip工具,但它只适用于CherryPy本地应用程序。因此,您需要使用第三方Gzip WSGI中间件(wsgigzip仅用作示例,我不知道哪个中间件工作得最好):
import cherrypy
import wsgigzip
application = wsgigzip.GzipMiddleware(bottle.default_app())
cherrypy.config.update({'server.socket_host': "0.0.0.0",
'server.socket_port': 8080})
cherrypy.tree.graft(application, "/")
cherrypy.engine.start()
cherrypy.engine.block()或者更好的是,使用uWSGI作为服务器,除了许多其他伟大的特性外,还可以使用可以做gzip。
发布于 2014-04-06 15:58:43
在黑暗中尝试一下(因为我不熟悉CherryPy):把它放到有"enable这里“注释的地方。
cherrypy.config.update({'tools.gzip.on': True})(灵感来源于这.)
运气好吗?
https://stackoverflow.com/questions/22892388
复制相似问题