bug496292-1.sjs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  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. if (request.getHeader("Accept") == "*/*") {
  11. file.append('blue.png');
  12. } else {
  13. file.append('red.png');
  14. }
  15. response.setStatusLine(request.httpVersion, 200, "OK");
  16. response.setHeader("Content-Type", "image/png", false);
  17. response.setHeader("Cache-Control", "no-cache", false);
  18. var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
  19. .createInstance(Components.interfaces.nsIFileInputStream);
  20. fileStream.init(file, 1, 0, false);
  21. var binaryStream = Components.classes['@mozilla.org/binaryinputstream;1']
  22. .createInstance(Components.interfaces.nsIBinaryInputStream);
  23. binaryStream.setInputStream(fileStream);
  24. response.bodyOutputStream.writeFrom(binaryStream, binaryStream.available());
  25. binaryStream.close();
  26. fileStream.close();
  27. }