diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /netwerk/test/browser/early_hint_asset.sjs | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/browser/early_hint_asset.sjs')
-rw-r--r-- | netwerk/test/browser/early_hint_asset.sjs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/netwerk/test/browser/early_hint_asset.sjs b/netwerk/test/browser/early_hint_asset.sjs new file mode 100644 index 0000000000..84a3dba37e --- /dev/null +++ b/netwerk/test/browser/early_hint_asset.sjs @@ -0,0 +1,51 @@ +"use strict"; + +function handleRequest(request, response) { + let hinted = + request.hasHeader("X-Moz") && request.getHeader("X-Moz") === "early hint"; + let count = JSON.parse(getSharedState("earlyHintCount")); + if (hinted) { + count.hinted += 1; + } else { + count.normal += 1; + } + setSharedState("earlyHintCount", JSON.stringify(count)); + + let content = ""; + Cu.importGlobalProperties(["URLSearchParams"]); + let qs = new URLSearchParams(request.queryString); + let asset = qs.get("as"); + + if (qs.get("cached") === "1") { + response.setHeader("Cache-Control", "max-age=604800", false); + } else { + response.setHeader("Cache-Control", "no-cache", false); + } + + if (asset === "image") { + response.setHeader("Content-Type", "image/png", false); + // set to green/black horizontal stripes (71 bytes) + content = atob( + hinted + ? "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAADklEQVQIW2OU+i/FAAcADoABNV8XGBMAAAAASUVORK5CYII=" + : "iVBORw0KGgoAAAANSUhEUgAAAAIAAAACCAIAAAD91JpzAAAAE0lEQVQIW2P4//+/N8MkBiAGsgA1bAe1SzDY8gAAAABJRU5ErkJggg==" + ); + } else if (asset === "style") { + response.setHeader("Content-Type", "text/css", false); + // green background on hint response, purple response otherwise + content = `#square { background: ${hinted ? "#1aff1a" : "#4b0092"}`; + } else if (asset === "script") { + response.setHeader("Content-Type", "application/javascript", false); + // green background on hint response, purple response otherwise + content = `window.onload = function() { + document.getElementById('square').style.background = "${ + hinted ? "#1aff1a" : "#4b0092" + }"; + }`; + } else if (asset === "fetch") { + response.setHeader("Content-Type", "text/plain", false); + content = hinted ? "hinted" : "normal"; + } + + response.write(content); +} |