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 parseQueryString(str) |
michael@0 | 2 | { |
michael@0 | 3 | if (str == "") |
michael@0 | 4 | return {}; |
michael@0 | 5 | |
michael@0 | 6 | var paramArray = str.split("&"); |
michael@0 | 7 | var regex = /^([^=]+)=(.*)$/; |
michael@0 | 8 | var params = {}; |
michael@0 | 9 | for (var i = 0, sz = paramArray.length; i < sz; i++) |
michael@0 | 10 | { |
michael@0 | 11 | var match = regex.exec(paramArray[i]); |
michael@0 | 12 | if (!match) |
michael@0 | 13 | throw "Bad parameter in queryString! '" + paramArray[i] + "'"; |
michael@0 | 14 | params[decodeURIComponent(match[1])] = decodeURIComponent(match[2]); |
michael@0 | 15 | } |
michael@0 | 16 | |
michael@0 | 17 | return params; |
michael@0 | 18 | } |
michael@0 | 19 | |
michael@0 | 20 | function getPosition(expectedAccessToken, providedAccessToken, desiredAccessToken) |
michael@0 | 21 | { |
michael@0 | 22 | var response = { |
michael@0 | 23 | status: "OK", |
michael@0 | 24 | location: { |
michael@0 | 25 | lat: providedAccessToken ? |
michael@0 | 26 | (expectedAccessToken == providedAccessToken ? 200 : 404) : 200, |
michael@0 | 27 | lng: -122.08769, |
michael@0 | 28 | }, |
michael@0 | 29 | accuracy: 100, |
michael@0 | 30 | access_token: desiredAccessToken |
michael@0 | 31 | }; |
michael@0 | 32 | |
michael@0 | 33 | return JSON.stringify(response); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | function handleRequest(request, response) |
michael@0 | 37 | { |
michael@0 | 38 | var params = parseQueryString(request.queryString); |
michael@0 | 39 | |
michael@0 | 40 | response.setStatusLine("1.0", 200, "OK"); |
michael@0 | 41 | response.setHeader("Cache-Control", "no-cache", false); |
michael@0 | 42 | response.setHeader("Content-Type", "aplication/x-javascript", false); |
michael@0 | 43 | response.write(getPosition(params.expected_access_token, params.access_token, |
michael@0 | 44 | params.desired_access_token)); |
michael@0 | 45 | } |