Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 redirectstate = "/image/test/mochitest/bug497665.sjs"; |
michael@0 | 13 | if (getState(redirectstate) == "") { |
michael@0 | 14 | file.append('blue.png'); |
michael@0 | 15 | setState(redirectstate, "red"); |
michael@0 | 16 | } else { |
michael@0 | 17 | file.append('red.png'); |
michael@0 | 18 | setState(redirectstate, ""); |
michael@0 | 19 | } |
michael@0 | 20 | |
michael@0 | 21 | response.setHeader("Cache-Control", "max-age=3600", false); |
michael@0 | 22 | |
michael@0 | 23 | var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1'] |
michael@0 | 24 | .createInstance(Components.interfaces.nsIFileInputStream); |
michael@0 | 25 | fileStream.init(file, 1, 0, false); |
michael@0 | 26 | var binaryStream = Components.classes['@mozilla.org/binaryinputstream;1'] |
michael@0 | 27 | .createInstance(Components.interfaces.nsIBinaryInputStream); |
michael@0 | 28 | binaryStream.setInputStream(fileStream); |
michael@0 | 29 | |
michael@0 | 30 | response.bodyOutputStream.writeFrom(binaryStream, binaryStream.available()); |
michael@0 | 31 | |
michael@0 | 32 | binaryStream.close(); |
michael@0 | 33 | fileStream.close(); |
michael@0 | 34 | } |