content/base/test/file_mixed_content_server.sjs

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial