beacon-redirect-handler.sjs (1645B)
1 /* 2 * TestSever customized specifically for the needs of: 3 * Bug 1280692 - sendBeacon() should follow 30x redirect 4 * 5 * Here is a sequence of the test: 6 * [1] sendBeacon (identified by the queryString 'beacon') which gets redirected 7 * [2] redirected sendBeacon (identified by the queryString 'redirected') which 8 * updates the state idniciating that redirected sendBeacon succeeds. 9 * [3] xhr request (identified by the queryString 'verifyRedirectDidSucceed') 10 * which checks if the state was not changed from 'reset' to 'gree'. If the channel 11 * woulnd't be blocked correctly the redirected channel would set the state to 'red'. 12 * 13 */ 14 15 function handleRequest(request, response) { 16 response.setHeader("Cache-Control", "no-cache, must-revalidate", false); 17 18 // [Sequence 3] 19 if (request.queryString === "verifyRedirectDidSucceed") { 20 var redirectState = getState("redirectState"); 21 response.write(redirectState); 22 return; 23 } 24 25 // [Sequence 1] 26 if (request.queryString === "beacon") { 27 setState("redirectState", "reset"); 28 var newLocation = 29 "http://mochi.test:8888/tests/dom/tests/mochitest/beacon/beacon-redirect-handler.sjs?redirected"; 30 response.setStatusLine("1.1", 302, "Found"); 31 response.setHeader("Location", newLocation, false); 32 return; 33 } 34 35 // [Sequence 2] 36 if (request.queryString === "redirected") { 37 setState("redirectState", "green"); 38 response.setStatusLine(null, 200, "OK"); 39 return; 40 } 41 42 // we should never get here, but just in case let's 43 // set the state to something unexpected 44 setState("redirectState", "red"); 45 response.setStatusLine(null, 200, "OK"); 46 }