summaryrefslogtreecommitdiffstats
path: root/dom/media/test/redirect.sjs
blob: 1653e8efc0762a379f206427e909bcd508f37906 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
function parseQuery(request, key) {
  var params = request.queryString.split('&');
  for (var j = 0; j < params.length; ++j) {
    var p = params[j];
	if (p == key)
	  return true;
    if (p.indexOf(key + "=") == 0)
	  return p.substring(key.length + 1);
	if (p.indexOf("=") < 0 && key == "")
	  return p;
  }
  return false;
}

// Return file content for the first request with a given key.
// All subsequent requests return a redirect to a different-origin resource.
function handleRequest(request, response)
{
  var domain = parseQuery(request, "domain");
  var file = parseQuery(request, "file");
  var allowed = parseQuery(request, "allowed");

  response.setStatusLine(request.httpVersion, 303, "See Other");
  response.setHeader("Location", "http://" + domain + "/tests/dom/media/test/" + (allowed ? "allowed.sjs?" : "") + file);
  response.setHeader("Content-Type", "text/html");
}