Fri, 16 Jan 2015 18:13:44 +0100
Integrate suggestion from review to improve consistency with existing code.
michael@0 | 1 | function handleRequest(request, response) |
michael@0 | 2 | { |
michael@0 | 3 | var file = Components.classes["@mozilla.org/file/directory_service;1"] |
michael@0 | 4 | .getService(Components.interfaces.nsIProperties) |
michael@0 | 5 | .get("CurWorkD", Components.interfaces.nsIFile); |
michael@0 | 6 | |
michael@0 | 7 | file.append("tests"); |
michael@0 | 8 | file.append("image"); |
michael@0 | 9 | file.append("test"); |
michael@0 | 10 | file.append("mochitest"); |
michael@0 | 11 | |
michael@0 | 12 | var filestate = "/image/test/mochitest/bug671906.sjs"; |
michael@0 | 13 | if (getState(filestate) == "") { |
michael@0 | 14 | file.append('blue.png'); |
michael@0 | 15 | setState(filestate, "red"); |
michael@0 | 16 | } else { |
michael@0 | 17 | file.append('red.png'); |
michael@0 | 18 | setState(filestate, ""); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | // Set the expires date to some silly time in the future so we're sure to |
michael@0 | 22 | // *want* to cache this image. |
michael@0 | 23 | var date = new Date(); |
michael@0 | 24 | date.setFullYear(date.getFullYear() + 1); |
michael@0 | 25 | response.setHeader("Expires", date.toUTCString(), false); |
michael@0 | 26 | |
michael@0 | 27 | var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1'] |
michael@0 | 28 | .createInstance(Components.interfaces.nsIFileInputStream); |
michael@0 | 29 | fileStream.init(file, 1, 0, false); |
michael@0 | 30 | |
michael@0 | 31 | response.bodyOutputStream.writeFrom(fileStream, fileStream.available()); |
michael@0 | 32 | |
michael@0 | 33 | fileStream.close(); |
michael@0 | 34 | |
michael@0 | 35 | response.setHeader("Access-Control-Allow-Origin", "*", false); |
michael@0 | 36 | } |