content/media/test/redirect.sjs

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

     1 function parseQuery(request, key) {
     2   var params = request.queryString.split('&');
     3   for (var j = 0; j < params.length; ++j) {
     4     var p = params[j];
     5 	if (p == key)
     6 	  return true;
     7     if (p.indexOf(key + "=") == 0)
     8 	  return p.substring(key.length + 1);
     9 	if (p.indexOf("=") < 0 && key == "")
    10 	  return p;
    11   }
    12   return false;
    13 }
    15 // Return file content for the first request with a given key.
    16 // All subsequent requests return a redirect to a different-origin resource.
    17 function handleRequest(request, response)
    18 {
    19   var domain = parseQuery(request, "domain");
    20   var file = parseQuery(request, "file");
    21   var allowed = parseQuery(request, "allowed");
    23   response.setStatusLine(request.httpVersion, 303, "See Other");
    24   response.setHeader("Location", "http://" + domain + "/tests/content/media/test/" + (allowed ? "allowed.sjs?" : "") + file);
    25   response.setHeader("Content-Type", "text/html");
    26 }

mercurial