file_downgrade_request_upgrade_request.sjs (1692B)
1 // Custom *.sjs file specifically for the needs of Bug 1706126 2 "use strict"; 3 // subdomain of example.com 4 const REDIRECT_302 = 5 "http://www.redirect-example.com/tests/dom/security/test/https-first/file_downgrade_request_upgrade_request.sjs"; 6 7 const RESPONSE_SUCCESS = ` 8 <html> 9 <body> 10 send message, upgraded 11 <script type="application/javascript"> 12 let scheme = document.location.protocol; 13 window.opener.postMessage({result: 'upgraded', scheme: scheme}, '*'); 14 </script> 15 </body> 16 </html>`; 17 18 const RESPONSE_UNEXPECTED = ` 19 <html> 20 <body> 21 send message, error 22 <script type="application/javascript"> 23 let scheme = document.location.protocol; 24 window.opener.postMessage({result: 'error', scheme: scheme}, '*'); 25 </script> 26 </body> 27 </html>`; 28 29 function handleRequest(request, response) { 30 // avoid confusing cache behaviour 31 response.setHeader("Cache-Control", "no-cache", false); 32 response.setHeader("Content-Type", "text/html", false); 33 34 // if the scheme is https and it is the initial request time it out 35 if (request.scheme === "https" && request.host === "redirect-example.com") { 36 // Simulating a timeout by processing the https request 37 response.processAsync(); 38 return; 39 } 40 if (request.scheme === "http" && request.host === "redirect-example.com") { 41 response.setStatusLine("1.1", 302, "Found"); 42 response.setHeader("Location", REDIRECT_302, false); 43 return; 44 } 45 // if the request was sent to subdomain 46 if (request.host.startsWith("www.")) { 47 response.write(RESPONSE_SUCCESS); 48 return; 49 } 50 // We should never arrive here, just in case send 'error' 51 response.write(RESPONSE_UNEXPECTED); 52 }