diff --git a/clear-site-data/clear-cache.https.html b/clear-site-data/clear-cache.https.html new file mode 100644 index 00000000000000..8cdaf2a5527198 --- /dev/null +++ b/clear-site-data/clear-cache.https.html @@ -0,0 +1,110 @@ + + + + + + + + + diff --git a/clear-site-data/support/clear-site-data-cache.py b/clear-site-data/support/clear-site-data-cache.py new file mode 100644 index 00000000000000..87107693b46edb --- /dev/null +++ b/clear-site-data/support/clear-site-data-cache.py @@ -0,0 +1,69 @@ +""" +Loaded in Step 2/4/Optional 6 (/clear-site-data/clear-cache.https.html) +Sending Message for Step 3/5/Optional 7 (/clear-site-data/clear-cache.https.html) +""" +import uuid + +def main(request, response): + # type of response: + # - "single_html": Main page html file with a different postMessage uuid on each response + # - "json": Json that always responds with a different uuid in a single-element array + # - "html_embed_json": Main page html that embeds a cachable version of the above json + response_type = request.GET.first(b"response") + + cache_helper = request.GET.first(b"cache_helper") + + # force enable caching when present or force disable if not + cache = b"cache" in request.GET + clear = None + if b"clear" in request.GET: + clear = request.GET.first(b"clear") + if b"clear_first" in request.GET: + if request.server.stash.take(cache_helper) is None: + clear = request.GET.first(b"clear_first") + request.server.stash.put(cache_helper, ()) + + headers = [] + if response_type == b"json": + headers += [(b"Content-Type", b"application/json")] + else: + headers += [(b"Content-Type", b"text/html")] + + if cache: + headers += [(b"cache-control", b"public, max-age=31536000, immutable")] + else: + headers += [(b"cache-control", b"no-store")] + + if clear is not None: + if clear == b"all": + headers += [(b"Clear-Site-Data", b'"*"')] + else: + headers += [(b"Clear-Site-Data", b'"' + clear + b'"')] + + if response_type == b"single_html": + # send unique UUID. Cache got cleared when uuids don't match. + content = f''' + + + {request.url} + ''' + elif response_type == b"json": + # send unique UUID. helper for below "html_embed_json" + content = f'''["{uuid.uuid4()}"]''' + elif response_type == b"html_embed_json": + url = request.url_parts.path + "?response=json&cache&cache_helper=" + cache_helper.decode() + content = f''' + + + {request.url}
+ {url} + ''' + + + return 200, headers, content