file_slow_non_standard_port.sjs (1416B)
1 // Custom *.sjs file specifically for the needs of Bug 1709552 2 "use strict"; 3 4 const RESPONSE_SUCCESS = ` 5 <html> 6 <body> 7 send message, downgraded 8 <script type="application/javascript"> 9 let scheme = document.location.protocol; 10 window.opener.postMessage({result: 'downgraded', scheme: scheme}, '*'); 11 </script> 12 </body> 13 </html>`; 14 15 const RESPONSE_UNEXPECTED = ` 16 <html> 17 <body> 18 send message, error 19 <script type="application/javascript"> 20 let scheme = document.location.protocol; 21 window.opener.postMessage({result: 'Error', scheme: scheme }, '*'); 22 </script> 23 </body> 24 </html>`; 25 26 function handleRequest(request, response) { 27 // avoid confusing cache behaviour 28 response.setHeader("Cache-Control", "no-cache", false); 29 response.setHeader("Content-Type", "text/html", false); 30 31 let query = request.queryString; 32 // If the scheme is not https then we rather fall through and display unexpected content 33 if (query.scheme === "https") { 34 // We should never arrive here, just in case send something unexpected 35 response.write(RESPONSE_UNEXPECTED); 36 return; 37 } 38 // Use a busy loop and slow down the response by one second 39 const delayMs = 1000; 40 const start = Date.now(); 41 while (Date.now() < start + delayMs) { 42 continue; 43 } 44 // We should arrive here when the redirection was downraded successful 45 response.write(RESPONSE_SUCCESS); 46 }