summaryrefslogtreecommitdiffstats
path: root/dom/security/test/general/file_block_script_wrong_mime_server.sjs
blob: d034c797a4c79394fea1134446be0d958d558c37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Custom *.sjs specifically for the needs of:
// Bug 1288361 - Block scripts with wrong MIME type

"use strict";

const WORKER = `
  onmessage = function(event) {
    postMessage("worker-loaded");
  };`;

function handleRequest(request, response) {
  const query = new URLSearchParams(request.queryString);

  // avoid confusing cache behaviors
  response.setHeader("Cache-Control", "no-cache", false);

  // Set MIME type
  response.setHeader("Content-Type", query.get("mime"), false);

  // Deliver response
  switch (query.get("type")) {
    case "script":
      response.write("");
      break;
    case "worker":
      response.write(WORKER);
      break;
    case "worker-import":
      response.write(
        `importScripts("file_block_script_wrong_mime_server.sjs?type=script&mime=${query.get(
          "mime"
        )}");`
      );
      response.write(WORKER);
      break;
  }
}