1 function parseQuery(request, key) {
2 var params = request.queryString.split("&");
3 for (var j = 0; j < params.length; ++j) {
8 if (p.indexOf(key + "=") == 0) {
9 return p.substring(key.length + 1);
11 if (p.indexOf("=") < 0 && key == "") {
18 function handleRequest(request, response) {
19 var name = parseQuery(request, "name");
20 var type = parseQuery(request, "type");
21 var cors = parseQuery(request, "cors");
22 var file = Cc["@mozilla.org/file/directory_service;1"]
23 .getService(Ci.nsIProperties)
24 .get("CurWorkD", Ci.nsIFile);
25 var fis = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
28 var bis = Cc["@mozilla.org/binaryinputstream;1"].createInstance(
29 Ci.nsIBinaryInputStream
31 var split = name.split("/");
32 for (var i = 0; i < split.length; ++i) {
33 file.append(split[i]);
35 fis.init(file, -1, -1, false);
36 bis.setInputStream(fis);
37 var bytes = bis.readBytes(bis.available());
38 response.setHeader("Content-Length", "" + bytes.length, false);
39 response.setHeader("Content-Type", type, false);
40 if (cors == "anonymous") {
41 response.setHeader("Access-Control-Allow-Origin", "*", false);
42 } else if (cors == "use-credentials") {
44 "Access-Control-Allow-Origin",
45 "http://mochi.test:8888",
48 response.setHeader("Access-Control-Allow-Credentials", "true", false);
50 response.write(bytes, bytes.length);