在aiohttp中为静态文件启用gzip压缩

问题描述:

我试图在静态文件中的aiohttp中启用压缩。我试图创建一个自定义的响应:在aiohttp中为静态文件启用gzip压缩

import aiohttp 

class GzipResponse(aiohttp.web.StreamResponse): 
    def __init__(self, *args, **kwargs): 
     super().__init__(*args, **kwargs) 
     self.enable_compression() 

,并增加一条,作为工厂的静态路由:

app.router.add_static("prefix", "path", response_factory=GzipResponse) 

,但它不工作。

也许它不起作用,因为如果设置了压缩,当前sendfile方法不会切换回退。

+0

我可能是错的,但似乎'aiohttp.file_sender.FileSender._sendfile_fallback()'方法似乎不压缩发送的内容。 –

+0

是的。 个人我现在不在意静态文件压缩 - 我的待办事项列表中有更重要的问题。 –

+0

不是问题,nginx是要走的路:) –