在我的 Django 应用程序的 views.py 中,我在尝试设置以下 HTTP 标头字段后返回一个 HttpResponse 对象:
# Create a Response Object with the content to return
response = HttpResponse("%s"%(output_display),mimetype='text/html')
response['Cache-Control'] = 'must-revalidate, max-age=20'
response['Vary'] = 'Accept-Encoding'
response['Transfer-Encoding'] = 'gzip'
#response['Content-Encoding'] = 'gzip'
response['Connection'] = 'close'
#response['Content-Type'] = 'text/html'
response['Content-Length'] = '%s'%(len(output_display))
return response
然后我使用带有 FireFox 的 Live HTTP Headers 插件捕获输出,它看起来像:
HTTP/1.1 200 OK
Date: Sun, 10 Mar 2013 14:55:09 GMT
Server: Apache/2.2.22 (Ubuntu)
Transfer-Encoding: gzip, chunked <---------- Why 'chunked'?
Vary: Accept-Encoding
Connection: close
Cache-Control: must-revalidate, max-age=20
Content-Encoding: gzip
Content-Type: text/html <---------------------- No Content-Length even though I set it?
X-Pad: avoid browser bug
我正在尝试使用 Apache2 的 mem_cache 进行缓存,因此我需要设置 Content-Length 并且不能为 Transfer-Encoding 设置“分块”。
我的 Apache2 mem_cache.conf 看起来像(大量仅用于测试):
<IfModule mod_mem_cache.c>
CacheEnable mem /
MCacheSize 10000
MCacheMaxObjectCount 10000000
MCacheMinObjectSize 1
MCacheMaxObjectSize 10000000
MCacheMaxStreamingBuffer 10000000
</IfModule>
但是,即使我在响应代码中明确设置了 Content-Length 和 Transfer-Encoding ,也会自动插入“chunked”,因此我的 Content-Length 不会受到尊重。为什么是这样?如何解决此问题以获得所需的响应?谢谢 -