file_downgrade_bad_responses.sjs (2095B)
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 window.opener.postMessage({result: 'downgraded', scheme: 'http'}, '*'); 10 </script> 11 </body> 12 </html>`; 13 14 const RESPONSE_UNEXPECTED = ` 15 <html> 16 <body> 17 send message, error 18 <script type="application/javascript"> 19 window.opener.postMessage({result: 'Error', scheme: 'http'}, '*'); 20 </script> 21 </body> 22 </html>`; 23 24 function handleRequest(request, response) { 25 // avoid confusing cache behaviour 26 response.setHeader("Cache-Control", "no-cache", false); 27 response.setHeader("Content-Type", "text/html", false); 28 29 let query = request.queryString; 30 // if the scheme is not https and it is the initial request 31 // then we rather fall through and display unexpected content 32 if (request.scheme === "https") { 33 if (query === "test1a") { 34 response.setStatusLine("1.1", 400, "Bad Request"); 35 response.write("Bad Request\n"); 36 return; 37 } 38 39 if (query === "test2a") { 40 response.setStatusLine("1.1", 403, "Forbidden"); 41 response.write("Forbidden\n"); 42 return; 43 } 44 45 if (query === "test3a") { 46 response.setStatusLine("1.1", 404, "Not Found"); 47 response.write("Not Found\n"); 48 return; 49 } 50 if (query === "test4a") { 51 response.setStatusLine("1.1", 416, "Requested Range Not Satisfiable"); 52 response.write("Requested Range Not Satisfiable\n"); 53 return; 54 } 55 if (query === "test5a") { 56 response.setStatusLine("1.1", 418, "I'm a teapot"); 57 response.write("I'm a teapot\n"); 58 return; 59 } 60 if (query == "test6a") { 61 // Simulating a timeout by processing the https request 62 response.processAsync(); 63 return; 64 } 65 66 // We should never arrive here, just in case send something unexpected 67 response.write(RESPONSE_UNEXPECTED); 68 return; 69 } 70 71 // We should arrive here when the redirection was downraded successful 72 response.write(RESPONSE_SUCCESS); 73 }