Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
michael@0 | 1 | function parseQuery(request, key) { |
michael@0 | 2 | var params = request.queryString.split('&'); |
michael@0 | 3 | for (var j = 0; j < params.length; ++j) { |
michael@0 | 4 | var p = params[j]; |
michael@0 | 5 | if (p == key) |
michael@0 | 6 | return true; |
michael@0 | 7 | if (p.indexOf(key + "=") == 0) |
michael@0 | 8 | return p.substring(key.length + 1); |
michael@0 | 9 | if (p.indexOf("=") < 0 && key == "") |
michael@0 | 10 | return p; |
michael@0 | 11 | } |
michael@0 | 12 | return false; |
michael@0 | 13 | } |
michael@0 | 14 | |
michael@0 | 15 | function handleRequest(request, response) |
michael@0 | 16 | { |
michael@0 | 17 | var referer = request.hasHeader("Referer") ? request.getHeader("Referer") |
michael@0 | 18 | : undefined; |
michael@0 | 19 | if (referer == "http://mochi.test:8888/tests/content/media/test/test_referer.html") { |
michael@0 | 20 | var name = parseQuery(request, "name"); |
michael@0 | 21 | var type = parseQuery(request, "type"); |
michael@0 | 22 | var file = Components.classes["@mozilla.org/file/directory_service;1"]. |
michael@0 | 23 | getService(Components.interfaces.nsIProperties). |
michael@0 | 24 | get("CurWorkD", Components.interfaces.nsILocalFile); |
michael@0 | 25 | var fis = Components.classes['@mozilla.org/network/file-input-stream;1']. |
michael@0 | 26 | createInstance(Components.interfaces.nsIFileInputStream); |
michael@0 | 27 | var bis = Components.classes["@mozilla.org/binaryinputstream;1"]. |
michael@0 | 28 | createInstance(Components.interfaces.nsIBinaryInputStream); |
michael@0 | 29 | var paths = "tests/content/media/test/" + name; |
michael@0 | 30 | var split = paths.split("/"); |
michael@0 | 31 | for(var i = 0; i < split.length; ++i) { |
michael@0 | 32 | file.append(split[i]); |
michael@0 | 33 | } |
michael@0 | 34 | fis.init(file, -1, -1, false); |
michael@0 | 35 | bis.setInputStream(fis); |
michael@0 | 36 | var bytes = bis.readBytes(bis.available()); |
michael@0 | 37 | response.setHeader("Content-Length", ""+bytes.length, false); |
michael@0 | 38 | response.setHeader("Content-Type", type, false); |
michael@0 | 39 | response.write(bytes, bytes.length); |
michael@0 | 40 | bis.close(); |
michael@0 | 41 | } |
michael@0 | 42 | else { |
michael@0 | 43 | response.setStatusLine(request.httpVersion, 404, "Not found"); |
michael@0 | 44 | } |
michael@0 | 45 | } |