How to set http headers with different content type

末鹿安然 提交于 2019-12-25 06:46:34

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!