Wed, 31 Dec 2014 13:27:57 +0100
Ignore runtime configuration files generated during quality assurance.
michael@0 | 1 | const BinaryOutputStream = |
michael@0 | 2 | Components.Constructor("@mozilla.org/binaryoutputstream;1", |
michael@0 | 3 | "nsIBinaryOutputStream", |
michael@0 | 4 | "setOutputStream"); |
michael@0 | 5 | |
michael@0 | 6 | // this is simply a hex dump of a red square .PNG image |
michael@0 | 7 | const RED_SQUARE = |
michael@0 | 8 | [ |
michael@0 | 9 | 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A, 0x00, 0x00, |
michael@0 | 10 | 0x00, 0x0D, 0x49, 0x48, 0x44, 0x52, 0x00, 0x00, 0x00, 0x20, |
michael@0 | 11 | 0x00, 0x00, 0x00, 0x20, 0x08, 0x02, 0x00, 0x00, 0x00, 0xFC, |
michael@0 | 12 | 0x18, 0xED, 0xA3, 0x00, 0x00, 0x00, 0x01, 0x73, 0x52, 0x47, |
michael@0 | 13 | 0x42, 0x00, 0xAE, 0xCE, 0x1C, 0xE9, 0x00, 0x00, 0x00, 0x28, |
michael@0 | 14 | 0x49, 0x44, 0x41, 0x54, 0x48, 0xC7, 0xED, 0xCD, 0x41, 0x0D, |
michael@0 | 15 | 0x00, 0x00, 0x08, 0x04, 0xA0, 0xD3, 0xFE, 0x9D, 0x35, 0x85, |
michael@0 | 16 | 0x0F, 0x37, 0x28, 0x40, 0x4D, 0x6E, 0x75, 0x04, 0x02, 0x81, |
michael@0 | 17 | 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0xC1, 0x93, 0x60, 0x01, |
michael@0 | 18 | 0xA3, 0xC4, 0x01, 0x3F, 0x58, 0x1D, 0xEF, 0x27, 0x00, 0x00, |
michael@0 | 19 | 0x00, 0x00, 0x49, 0x45, 0x4E, 0x44, 0xAE, 0x42, 0x60, 0x82 |
michael@0 | 20 | ]; |
michael@0 | 21 | |
michael@0 | 22 | function handleRequest(request, response) |
michael@0 | 23 | { |
michael@0 | 24 | var query = {}; |
michael@0 | 25 | request.queryString.split('&').forEach(function (val) { |
michael@0 | 26 | var [name, value] = val.split('='); |
michael@0 | 27 | query[name] = unescape(value); |
michael@0 | 28 | }); |
michael@0 | 29 | |
michael@0 | 30 | response.setHeader("Cache-Control", "no-cache"); |
michael@0 | 31 | |
michael@0 | 32 | response.setStatusLine(request.httpVersion, 200, "OK"); |
michael@0 | 33 | response.setHeader("Content-Type", "text/plain", false); |
michael@0 | 34 | |
michael@0 | 35 | var log = getState("bug-879963-request-log") || ""; |
michael@0 | 36 | |
michael@0 | 37 | var stream = new BinaryOutputStream(response.bodyOutputStream); |
michael@0 | 38 | |
michael@0 | 39 | if (query["q"] == "init") { |
michael@0 | 40 | log = "init"; // initialize the log, and return a PNG image |
michael@0 | 41 | response.setHeader("Content-Type", "image/png", false); |
michael@0 | 42 | stream.writeByteArray(RED_SQUARE, RED_SQUARE.length); |
michael@0 | 43 | } else if (query["q"] == "image") { |
michael@0 | 44 | log = log + ";" + query["q"]; |
michael@0 | 45 | response.setHeader("Content-Type", "image/png", false); |
michael@0 | 46 | stream.writeByteArray(RED_SQUARE, RED_SQUARE.length); |
michael@0 | 47 | } else if (query["q"] == "font") { |
michael@0 | 48 | log = log + ";" + query["q"]; |
michael@0 | 49 | // we don't provide a real font; that's ok, OTS will just reject it |
michael@0 | 50 | response.write("Junk"); |
michael@0 | 51 | } else if (query["q"] == "report") { |
michael@0 | 52 | // don't include the actual "report" request in the log we return |
michael@0 | 53 | response.write(log); |
michael@0 | 54 | } else { |
michael@0 | 55 | log = log + ";" + query["q"]; |
michael@0 | 56 | response.setStatusLine(request.httpVersion, 404, "Not Found"); |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | setState("bug-879963-request-log", log); |
michael@0 | 60 | } |