Created
September 9, 2020 11:50
-
-
Save nickrussler/cd74ac1c07884938b205556030414d34 to your computer and use it in GitHub Desktop.
Test for browser handling of duplicate GET requests for the same resource
This file contains hidden or 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
#!/usr/bin/python | |
# coding: utf-8 | |
import time | |
from flask import Flask, make_response | |
from waitress import serve | |
import random | |
app = Flask(__name__) | |
@app.route('/') | |
def index(): | |
return ''' | |
<!DOCTYPE html> | |
<html> | |
<body> | |
<script> | |
fetch('/data.json').then(async r => console.log(await r.json())); | |
fetch('/data.json').then(async r => console.log(await r.json()));; | |
setTimeout(() => fetch('/data.json').then(async r => console.log(await r.json())), 2000); | |
</script> | |
</body> | |
</html> | |
''' | |
@app.route('/data.json') | |
def data(): | |
time.sleep(5) | |
response = make_response({"random": random.randint(0, 999999)}) | |
response.cache_control.max_age = 30 | |
return response | |
if __name__ == '__main__': | |
serve(app, host='0.0.0.0', port=8080, threads=8) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment