summaryrefslogtreecommitdiffstats
path: root/dom/security/test/sec-fetch/file_redirect.sjs
blob: 84c2c399138488bdcdd44c73f0f80482de7b55e3 (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
const SITE_META_REDIRECT = `
<html>
  <head>
    <meta http-equiv="refresh" content="0; url='https://example.com/tests/dom/security/test/sec-fetch/file_redirect.sjs?redirect302'">
  </head>
  <body>
    META REDIRECT
  </body>
</html>
`;

const REDIRECT_302 =
  "https://example.com/tests/dom/security/test/sec-fetch/file_redirect.sjs?pageC";

function handleRequest(req, res) {
  // avoid confusing cache behaviour
  res.setHeader("Cache-Control", "no-cache", false);
  res.setHeader("Content-Type", "text/html", false);

  switch (req.queryString) {
    case "meta":
      res.write(SITE_META_REDIRECT);
      return;
    case "redirect302":
      res.setStatusLine("1.1", 302, "Found");
      res.setHeader("Location", REDIRECT_302, false);
      return;
    case "pageC":
      res.write("<html><body>PAGE C</body></html>");
      return;
  }

  res.write(`<html><body>THIS SHOULD NEVER BE DISPLAYED</body></html>`);
}