content/base/test/file_mixed_content_server.sjs

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

     2 function handleRequest(request, response)
     3 {
     4   // get the Content-Type to serve from the query string
     5   var contentType = null;
     6   request.queryString.split('&').forEach( function (val) {
     7      var [name, value] = val.split('=');
     8        if (name == "type") {
     9          contentType = unescape(value);
    10        }
    11   });
    13   // avoid confusing cache behaviors
    14   response.setHeader("Cache-Control", "no-cache", false);
    16   switch (contentType) {
    17     case "iframe":
    18       response.setHeader("Content-Type", "text/html", false);
    19       response.write("frame content");
    20       break;
    22     case "script":
    23       response.setHeader("Content-Type", "application/javascript", false);
    24       break;
    26     case "stylesheet":
    27       response.setHeader("Content-Type", "text/css", false);
    28       break;
    30     case "object":
    31       response.setHeader("Content-Type", "application/x-test", false);
    32       break;
    34    case "xhr":
    35       response.setHeader("Content-Type", "text/xml", false);
    36       response.setHeader("Access-Control-Allow-Origin", "https://example.com");
    37       response.write('<?xml version="1.0" encoding="UTF-8" ?><test></test>');
    38       break;
    40     default:
    41       response.setHeader("Content-Type", "text/html", false);
    42       response.write("<html><body>Hello World</body></html>");
    43       break;
    44   }
    45 }

mercurial