bug490949.sjs 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. function handleRequest(request, response)
  2. {
  3. var file = Components.classes["@mozilla.org/file/directory_service;1"]
  4. .getService(Components.interfaces.nsIProperties)
  5. .get("CurWorkD", Components.interfaces.nsIFile);
  6. file.append("tests");
  7. file.append("image");
  8. file.append("test");
  9. file.append("mochitest");
  10. var redirectstate = "/image/test/mochitest/bug490949.sjs";
  11. if (getState(redirectstate) == "") {
  12. file.append('blue.png');
  13. setState(redirectstate, "red");
  14. } else {
  15. file.append('red.png');
  16. setState(redirectstate, "");
  17. }
  18. response.setHeader("Cache-Control", "no-cache", false);
  19. var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
  20. .createInstance(Components.interfaces.nsIFileInputStream);
  21. fileStream.init(file, 1, 0, false);
  22. var binaryStream = Components.classes['@mozilla.org/binaryinputstream;1']
  23. .createInstance(Components.interfaces.nsIBinaryInputStream);
  24. binaryStream.setInputStream(fileStream);
  25. response.bodyOutputStream.writeFrom(binaryStream, binaryStream.available());
  26. binaryStream.close();
  27. fileStream.close();
  28. }