[英]Disable caching in web.py web server, ignoring HTTP header
我在python中有一个Web应用程序,该Web服务器是使用库web.py实现的。
但是,当浏览器在Web服务器上(例如,在/static/index.html上)发送请求时,它在http标头中包含“ IF-MATCH-NONE”和“ IF-MODIFIED-SINCE”字段,并且服务器会检查如果html页面请求自上次以来已被修改(以及服务器响应为http 304-未修改)...
在任何情况下,即使未经修改,如何强制html页面响应?
Web服务器的代码如下。
import web
urls= (
'/', 'redirect',
'/static/*','index2',
'/home/','process'
)
app=web.application(urls,globals())
class redirect:
def GET(self):
..
return web.redirect("/static/index.html")
def POST(self):
..
raise web.seeother("/static/index.html")
class index2:
def GET(self):
...
some checks
....
if __name__=="__main__":
app.run()
您需要在响应标头中添加Cache-Control
字段:
web.header("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store")
例如:
import web
urls = ("/.*", "hello")
app = web.application(urls, globals())
class hello(object):
def GET(self):
web.header("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store")
return "Hello, world!"
if __name__ == "__main__":
app.run()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.