From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../test/browser/early_hint_csp_options_html.sjs | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 netwerk/test/browser/early_hint_csp_options_html.sjs (limited to 'netwerk/test/browser/early_hint_csp_options_html.sjs') diff --git a/netwerk/test/browser/early_hint_csp_options_html.sjs b/netwerk/test/browser/early_hint_csp_options_html.sjs new file mode 100644 index 0000000000..17c286f8ac --- /dev/null +++ b/netwerk/test/browser/early_hint_csp_options_html.sjs @@ -0,0 +1,121 @@ +"use strict"; + +function handleRequest(request, response) { + Cu.importGlobalProperties(["URLSearchParams"]); + let qs = new URLSearchParams(request.queryString); + let asset = qs.get("as"); + let hinted = qs.get("hinted") !== "0"; + let httpCode = qs.get("code"); + let csp = qs.get("csp"); + let csp_in_early_hint = qs.get("csp_in_early_hint"); + let host = qs.get("host"); + + // eslint-disable-next-line mozilla/use-services + let uuidGenerator = Cc["@mozilla.org/uuid-generator;1"].getService( + Ci.nsIUUIDGenerator + ); + let uuid = uuidGenerator.generateUUID().toString(); + let url = `early_hint_pixel.sjs?as=${asset}&uuid=${uuid}`; + if (host) { + url = host + url; + } + + // write to raw socket + response.seizePower(); + + if (hinted) { + response.write("HTTP/1.1 103 Early Hint\r\n"); + if (csp_in_early_hint) { + response.write( + `Content-Security-Policy: ${csp_in_early_hint.replaceAll('"', "")}\r\n` + ); + } + response.write(`Link: <${url}>; rel=preload; as=${asset}\r\n`); + response.write("\r\n"); + } + + let body = ""; + if (asset === "image") { + body = ` + + + + + `; + } else if (asset === "style") { + body = ` + + + + + +

Test preload css

+
+ + + `; + } else if (asset === "script") { + body = ` + + + + + +

Test preload javascript

+
+ + + `; + } else if (asset === "fetch") { + body = ` + + + +

Test preload fetch

+

Fetching...

+ + + `; + } else if (asset === "font") { + body = ` + + + + + +

Test preload font

+ + + `; + } + + if (!httpCode) { + response.write(`HTTP/1.1 200 OK\r\n`); + } else { + response.write(`HTTP/1.1 ${httpCode} Error\r\n`); + } + response.write("Content-Type: text/html;charset=utf-8\r\n"); + response.write("Cache-Control: no-cache\r\n"); + response.write(`Content-Length: ${body.length}\r\n`); + if (csp) { + response.write(`Content-Security-Policy: ${csp.replaceAll('"', "")}\r\n`); + } + response.write("\r\n"); + response.write(body); + + response.finish(); +} -- cgit v1.2.3