问题
I have a webpage dynamically created via Python. Its purpose is to provide images, so the first line sets the content type:
Content-Type: image/png
I would like to set http headers, specifically cache controlling, but I'm not too sure how as the content type is not html, so I'm sure I cant put html style headers into it.
EDIT: The code starts simply:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import string, sys, math, os
print("Content-Type: image/png\n")
回答1:
Cache-Control, Content-Type and the like are HTTP headers, not "html style headers". You can use them regardless of the content-type.
回答2:
import string, sys, math, os
print("Cache-Control: max-age=" + str(86400 * 3650) + ", public")
print("Content-Type: image/png")
print("\n")
That sets the resource to expire in ten years.
来源:https://stackoverflow.com/questions/10727942/how-to-set-http-headers-with-different-content-type