def after_request(self, response):
accept_encoding = request.headers.get('Accept-Encoding', '')
if not accept_encoding:
return response
encodings = accept_encoding.split(',')
if 'gzip' not in encodings:
return response
if (200 > response.status_code >= 300) or len(response.data) < 500 or 'Content-Encoding' in response.headers:
return response
response.data = gzip.compress(response.data, compresslevel=self.compress_level)
response.headers['Content-Encoding'] = 'gzip'
response.headers['Content-Length'] = len(response.data)
return response
评论列表
文章目录