PageRenderTime 22ms CodeModel.GetById 17ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 1ms

/image/test/mochitest/bug497665.sjs

http://github.com/zpao/v8monkey
Unknown | 34 lines | 28 code | 6 blank | 0 comment | 0 complexity | bcec0a135af278de83082a8284f76a58 MD5 | raw file
 1function 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
 7  file.append("tests");
 8  file.append("image");
 9  file.append("test");
10  file.append("mochitest");
11
12  var redirectstate = "/image/test/mochitest/bug497665.sjs";
13  if (getState(redirectstate) == "") {
14    file.append('blue.png');
15    setState(redirectstate, "red");
16  } else {
17    file.append('red.png');
18    setState(redirectstate, "");
19  }
20
21  response.setHeader("Cache-Control", "max-age=3600", false);
22
23  var fileStream = Components.classes['@mozilla.org/network/file-input-stream;1']
24                   .createInstance(Components.interfaces.nsIFileInputStream);
25  fileStream.init(file, 1, 0, false);
26  var binaryStream = Components.classes['@mozilla.org/binaryinputstream;1']
27                     .createInstance(Components.interfaces.nsIBinaryInputStream);
28  binaryStream.setInputStream(fileStream);
29
30  response.bodyOutputStream.writeFrom(binaryStream, binaryStream.available());
31
32  binaryStream.close();
33  fileStream.close();
34}