Created
October 20, 2011 20:49
-
-
Save chadselph/1302343 to your computer and use it in GitHub Desktop.
redirect caching experiments
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
import flask | |
from gevent.pywsgi import WSGIServer | |
app = Flask(__name__) | |
app.debug = True | |
color = 'green' | |
@app.route("/js") | |
def canvas(): | |
headers = { | |
'Location': '/js/%s.js' % color, | |
'Cache-Control':'no-cache', | |
'Pragma': 'no-cache', | |
} | |
return flask.Response(status='303 See Other', headers=headers) | |
@app.route("/dontcachemebro") | |
def no_cache(): | |
from datetime import datetime | |
headers = { | |
'Cache-Control':'no-cache', | |
'Pragma': 'no-cache', | |
} | |
resp = str(datetime.now()) | |
return flask.Response(resp, headers=headers) | |
@app.route("/deploy/<new_color>", methods=["POST"]) | |
def deploy_color(new_color): | |
global color | |
color = new_color | |
return "" | |
@app.route("/js/<color>.js") | |
def make_canvas(color): | |
js = 'document.body.bgColor = "%s";' % color | |
headers = {'Content-Type': 'application/javascript', 'Expires': 'Fri, 30 Oct 2400 00:00:00 GMT'} | |
return flask.Response(js, headers=headers) | |
if __name__ == "__main__": | |
WSGIServer(('', 8084), app).serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<head> | |
<link href="data:image/x-icon;base64,AAABAAEAEBAAAAAAAABoBQAAFgAAACgAAAAQAAAAIAAAAAEACAAAAAAAAAEAAAAAAAAAAAAAAAEAAAAAAA..AMAK3WxwAOWT0AK4RgAKHOvQA4hWUAP4lqAD2MagBQm3kATKSBAECcdP//AAD8/wAA+H8AAPA/AADwPwAA4B8AAMAPAACABwAAAgMAAI8BAADfgAAA/8AAAP/AAAD/4QAA//MAAP//AAA=" rel="icon" type="image/x-icon" /> | |
</head> | |
<body> | |
<script type="text/javascript" src="/dontcachemebro"></script> | |
<script type="text/javascript" src="/js"></script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment