B2G/gecko/content/base/test/file_csp_redirects_resource.sjs
// can include. The resource may redirect to a different resource, if specified.
can include. The resource may redirect to a different resource, if specified.
can include . The resource may redirect to a different resource if specified .
function handleRequest(request, response)
{
  var query = {};
  request.queryString.split('&').forEach(function (val) {
    var [name, value] = val.split('=');
    query[name] = unescape(value);
  });
  var thisSite = "http://mochi.test:8888";
  var otherSite = "http://example.com";
  var resource = "/tests/content/base/test/file_csp_redirects_resource.sjs";
  response.setHeader("Cache-Control", "no-cache", false);
  if (query["redir"] == "same") {
    var loc = thisSite+resource+"?res="+query["res"]+"&testid="+query["id"];
    response.setStatusLine("1.1", 302, "Found");
    response.setHeader("Location", loc, false);
    return;
  }
  else if (query["redir"] == "other") {
    var loc = otherSite+resource+"?res="+query["res"]+"&testid="+query["id"];
    response.setStatusLine("1.1", 302, "Found");
    response.setHeader("Location", loc, false);
    return;
  }
  if (query["res"] == "font") {
    response.setHeader("Access-Control-Allow-Origin", "*", false);
    response.setHeader("Content-Type", "text/plain", false);
    response.write("font data...");
    return;
  }
  if (query["res"] == "iframe") {
    response.setHeader("Content-Type", "text/html", false);
    response.write("iframe content...");
    return;
  }
  if (query["res"] == "image") {
    response.setHeader("Content-Type", "image/gif", false);
    response.write("image data...");
    return;
  }
  if (query["res"] == "media") {
    response.setHeader("Content-Type", "video/ogg", false);
    response.write("video data...");
    return;
  }
  if (query["res"] == "object") {
    response.setHeader("Content-Type", "text/html", false);
    response.write("object data...");
    return;
  }
  if (query["res"] == "script") {
    response.setHeader("Content-Type", "application/javascript", false);
    response.write("some script...");
    return;
  }
  if (query["res"] == "style") {
    response.setHeader("Content-Type", "text/css", false);
    response.write("css data...");
    return;
  }
  if (query["res"] == "worker") {
    response.setHeader("Content-Type", "application/javascript", false);
    response.write("worker script data...");
    return;
  }
   that invokes XHR
  if (query["res"] == "xhr") {
    response.setHeader("Content-Type", "text/html", false);
    var resp = 'var x = new XMLHttpRequest(); x.open("GET", "' + otherSite +
               resource+'?res=xhr-resp&testid=xhr-src-redir", false); ' +
               'x.send(null);';
    response.write(resp);
    return;
  }
  if (query["res"] == "xhr-resp") {
    response.setHeader("Access-Control-Allow-Origin", "*", false);
    response.setHeader("Content-Type", "text/html", false);
    response.write('XHR response...');
    return;
  }
}
function handleRequest ( request , response ) { var query = { } ; request . queryString . split ( '&' ) . forEach ( function ( val ) { var [ name , value ] = val . split ( '=' ) ; query [ name ] = unescape ( value ) ; } ) ; var thisSite = "http://mochi.test:8888" ; var otherSite = "http://example.com" ; var resource = "/tests/content/base/test/file_csp_redirects_resource.sjs" ; response . setHeader ( "Cache-Control" , "no-cache" , false ) ; if ( query [ "redir" ] == "same" ) { var loc = thisSite + resource + "?res=" + query [ "res" ] + "&testid=" + query [ "id" ] ; response . setStatusLine ( "1.1" , 302 , "Found" ) ; response . setHeader ( "Location" , loc , false ) ; return ; } else if ( query [ "redir" ] == "other" ) { var loc = otherSite + resource + "?res=" + query [ "res" ] + "&testid=" + query [ "id" ] ; response . setStatusLine ( "1.1" , 302 , "Found" ) ; response . setHeader ( "Location" , loc , false ) ; return ; } if ( query [ "res" ] == "font" ) { response . setHeader ( "Access-Control-Allow-Origin" , "*" , false ) ; response . setHeader ( "Content-Type" , "text/plain" , false ) ; response . write ( "font data..." ) ; return ; } if ( query [ "res" ] == "iframe" ) { response . setHeader ( "Content-Type" , "text/html" , false ) ; response . write ( "iframe content..." ) ; return ; } if ( query [ "res" ] == "image" ) { response . setHeader ( "Content-Type" , "image/gif" , false ) ; response . write ( "image data..." ) ; return ; } if ( query [ "res" ] == "media" ) { response . setHeader ( "Content-Type" , "video/ogg" , false ) ; response . write ( "video data..." ) ; return ; } if ( query [ "res" ] == "object" ) { response . setHeader ( "Content-Type" , "text/html" , false ) ; response . write ( "object data..." ) ; return ; } if ( query [ "res" ] == "script" ) { response . setHeader ( "Content-Type" , "application/javascript" , false ) ; response . write ( "some script..." ) ; return ; } if ( query [ "res" ] == "style" ) { response . setHeader ( "Content-Type" , "text/css" , false ) ; response . write ( "css data..." ) ; return ; } if ( query [ "res" ] == "worker" ) { response . setHeader ( "Content-Type" , "application/javascript" , false ) ; response . write ( "worker script data..." ) ; return ; } if ( query [ "res" ] == "xhr" ) { response . setHeader ( "Content-Type" , "text/html" , false ) ; var resp = 'var x = new XMLHttpRequest(); x.open("GET", "' + otherSite + resource + '?res=xhr-resp&testid=xhr-src-redir", false); ' + 'x.send(null);' ; response . write ( resp ) ; return ; } if ( query [ "res" ] == "xhr-resp" ) { response . setHeader ( "Access-Control-Allow-Origin" , "*" , false ) ; response . setHeader ( "Content-Type" , "text/html" , false ) ; response . write ( 'XHR response...' ) ; return ; } }
can include.
can include .
// redirect to a resource on this site // redirect to a resource on a different site // not a redirect.  serve some content. // the content doesn't have to be valid, since we're only checking whether // the request for the content was sent or not. // downloadable font // iframe with arbitrary content // image // media content, e.g. Ogg video // plugin content, e.g. <object> // script // external stylesheet // web worker resource // script that invokes XHR // response to XHR