2016-04-28 85 views
2

我在python中有一个web应用程序,web服务器是通过库web.py来实现的。在web.py web服务器中禁用缓存,忽略HTTP标头

但是,当浏览器在Web服务器发送请求时,例如在/static/index.html上,它在http标题中包含字段'IF-MATCH-NONE'和'IF-MODIFIED-SINCE'并且服务器检查自上次以来是否修改了html页面请求(以及服务器对http 304的响应 - 未修改)...

如何在任何情况下强制响应html页面,即使它没有被修改?

网络服务器的代码如下。

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() 
+0

作为权宜之计,您可以配置流行的浏览器禁用缓存而“开发者控制台“已打开。这对我来说已经足够了。 – Gerard

回答

0

您需要添加响应头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()