2

I have a web application in python, the web server is implemented with library web.py.

But, when the browser send a request at the web server, at example on /static/index.html, it includes in http headers, the field 'IF-MATCH-NONE' and 'IF-MODIFIED-SINCE' and the server checks if the html page request has been modified since last time (and the server response with http 304 - Not Modified) ...

How can I force the response with the html page in any case, even if it hasn't been modified?

The code of web server is below.

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()
Kimas
  • 21
  • 5
  • As a stopgap measure, you can configure popular web browsers to disable cache while a "developer console" is open. This was sufficient for me. – Gerard Aug 26 '16 at 20:07

1 Answers1

0

You need to add Cache-Control field in response header:

web.header("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store")

For example:

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()
pbuck
  • 4,291
  • 2
  • 24
  • 36