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ヘッダープラグインを使用して出力をキャプチャすると、次のようになります。
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用に「チャンク」することはできません。
私のApache2mem_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は尊重されません。どうしてこれなの?どうすればこれを修正して目的の応答を得ることができますか?ありがとう -