summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fetch/stale-while-revalidate/resources
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/fetch/stale-while-revalidate/resources')
-rw-r--r--testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-css.py28
-rw-r--r--testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-image.py40
-rw-r--r--testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-script.py32
3 files changed, 100 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-css.py b/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-css.py
new file mode 100644
index 0000000000..b87668373a
--- /dev/null
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-css.py
@@ -0,0 +1,28 @@
+def main(request, response):
+
+ token = request.GET.first(b"token", None)
+ is_query = request.GET.first(b"query", None) != None
+ with request.server.stash.lock:
+ value = request.server.stash.take(token)
+ count = 0
+ if value != None:
+ count = int(value)
+ if is_query:
+ if count < 2:
+ request.server.stash.put(token, count)
+ else:
+ count = count + 1
+ request.server.stash.put(token, count)
+ if is_query:
+ headers = [(b"Count", count)]
+ content = b""
+ return 200, headers, content
+ else:
+ content = b"body { background: rgb(0, 128, 0); }"
+ if count > 1:
+ content = b"body { background: rgb(255, 0, 0); }"
+
+ headers = [(b"Content-Type", b"text/css"),
+ (b"Cache-Control", b"private, max-age=0, stale-while-revalidate=60")]
+
+ return 200, headers, content
diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-image.py b/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-image.py
new file mode 100644
index 0000000000..36e6fc0c9b
--- /dev/null
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-image.py
@@ -0,0 +1,40 @@
+import os.path
+
+from wptserve.utils import isomorphic_decode
+
+def main(request, response):
+
+ token = request.GET.first(b"token", None)
+ is_query = request.GET.first(b"query", None) != None
+ with request.server.stash.lock:
+ value = request.server.stash.take(token)
+ count = 0
+ if value != None:
+ count = int(value)
+ if is_query:
+ if count < 2:
+ request.server.stash.put(token, count)
+ else:
+ count = count + 1
+ request.server.stash.put(token, count)
+
+ if is_query:
+ headers = [(b"Count", count)]
+ content = b""
+ return 200, headers, content
+ else:
+ filename = u"green-16x16.png"
+ if count > 1:
+ filename = u"green-256x256.png"
+
+ path = os.path.join(os.path.dirname(isomorphic_decode(__file__)), u"../../../images", filename)
+ body = open(path, "rb").read()
+
+ response.add_required_headers = False
+ response.writer.write_status(200)
+ response.writer.write_header(b"content-length", len(body))
+ response.writer.write_header(b"Cache-Control", b"private, max-age=0, stale-while-revalidate=60")
+ response.writer.write_header(b"content-type", b"image/png")
+ response.writer.end_headers()
+
+ response.writer.write(body)
diff --git a/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-script.py b/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-script.py
new file mode 100644
index 0000000000..731cd80565
--- /dev/null
+++ b/testing/web-platform/tests/fetch/stale-while-revalidate/resources/stale-script.py
@@ -0,0 +1,32 @@
+import random, string
+
+def id_token():
+ letters = string.ascii_lowercase
+ return b''.join(random.choice(letters).encode("utf-8") for i in range(20))
+
+def main(request, response):
+ token = request.GET.first(b"token", None)
+ is_query = request.GET.first(b"query", None) != None
+ with request.server.stash.lock:
+ value = request.server.stash.take(token)
+ count = 0
+ if value != None:
+ count = int(value)
+ if is_query:
+ if count < 2:
+ request.server.stash.put(token, count)
+ else:
+ count = count + 1
+ request.server.stash.put(token, count)
+
+ if is_query:
+ headers = [(b"Count", count)]
+ content = u""
+ return 200, headers, content
+ else:
+ unique_id = id_token()
+ headers = [(b"Content-Type", b"text/javascript"),
+ (b"Cache-Control", b"private, max-age=0, stale-while-revalidate=60"),
+ (b"Unique-Id", unique_id)]
+ content = b"report('%s')" % unique_id
+ return 200, headers, content