summaryrefslogtreecommitdiffstats
path: root/dom/security/test/https-only/file_break_endless_upgrade_downgrade_loop.sjs
blob: a8a9083ef3fb2458c99287dc93392be17d727ded (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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// Custom *.sjs file specifically for the needs of Bug 1691888
"use strict";

const REDIRECT_META = `
  <html>
  <head>
    <meta http-equiv="refresh" content="0; url='http://example.com/tests/dom/security/test/https-only/file_break_endless_upgrade_downgrade_loop.sjs?test1b'">
  </head>
  <body>
    META REDIRECT
  </body>
  </html>`;

const REDIRECT_JS = `
  <html>
   <body>
     JS REDIRECT
     <script>
       let url= "http://example.com/tests/dom/security/test/https-only/file_break_endless_upgrade_downgrade_loop.sjs?test2b";
       window.location = url;
     </script>
   </body>
   </html>`;

const REDIRECT_302 =
  "http://example.com/tests/dom/security/test/https-only/file_break_endless_upgrade_downgrade_loop.sjs?test3b";

const REDIRECT_302_DIFFERENT_PATH =
  "http://example.com/tests/dom/security/test/https-only/file_user_gesture.html";

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

  // if the scheme is not https, meaning that the initial request did not
  // get upgraded, then we rather fall through and display unexpected content.
  if (request.scheme === "https") {
    let query = request.queryString;

    if (query === "test1a") {
      response.write(REDIRECT_META);
      return;
    }

    if (query === "test2a") {
      response.write(REDIRECT_JS);
      return;
    }

    if (query === "test3a") {
      response.setStatusLine("1.1", 302, "Found");
      response.setHeader("Location", REDIRECT_302, false);
      return;
    }

    if (query === "test4a") {
      response.setStatusLine("1.1", 302, "Found");
      response.setHeader("Location", REDIRECT_302_DIFFERENT_PATH, false);
      return;
    }
  }

  // we should never get here, just in case,
  // let's return something unexpected
  response.write("<html><body>DO NOT DISPLAY THIS</body></html>");
}