Bug 1443942 - Ensure redirect SJS' serve the correct content types. r?jya draft
authorChris Pearce <cpearce@mozilla.com>
Wed, 28 Mar 2018 16:51:04 +1300
changeset 779057 27dd68c9a1f607f85ccece081ad54a581d00b2e9
parent 779056 db7f0c61b64990623ef035b266cf052c45df1c76
child 779058 cd981c7dd553cc5099c14731722396507f688257
push id105646
push userbmo:cpearce@mozilla.com
push dateSun, 08 Apr 2018 22:04:39 +0000
reviewersjya
bugs1443942
milestone61.0a1
Bug 1443942 - Ensure redirect SJS' serve the correct content types. r?jya dynamic_redirect.sjs and midflight-redirect.sjs are serving files with "Content-Type: video/ogg", which is incorrect and could lead to problems given that we're not always asking it to serve Ogg files. So include the type be to served as a query parameter. MozReview-Commit-ID: 5f0PXy8lL3G
dom/media/test/dynamic_redirect.sjs
dom/media/test/midflight-redirect.sjs
dom/media/test/test_mediarecorder_principals.html
dom/media/test/test_midflight_redirect_blocked.html
--- a/dom/media/test/dynamic_redirect.sjs
+++ b/dom/media/test/dynamic_redirect.sjs
@@ -10,16 +10,17 @@ function parseQuery(query, key) {
 }
 
 // Return seek.ogv 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 query = request.queryString;
   var key = parseQuery(query, "key");
+  var type = parseQuery(query, "type") || "application/octet-stream";
   var resource = parseQuery(query, "res");
   var nested = parseQuery(query, "nested") || false;
 
   dump("Received request for key = "+ key +"\n");
   if (!nested) {
     if (getState(key) == "redirect") {
       var origin = request.host == "mochi.test" ? "example.org" : "mochi.test:8888";
       response.setStatusLine(request.httpVersion, 303, "See Other");
@@ -55,13 +56,13 @@ function handleRequest(request, response
   let contentRange = "bytes "+ from +"-"+ to +"/"+ bytes.length;
   let contentLength = (to - from + 1).toString();
   dump("Response Content-Range = "+ contentRange +"\n");
   dump("Response Content-Length = "+ contentLength +"\n");
 
   response.setStatusLine(request.httpVersion, 206, "Partial Content");
   response.setHeader("Content-Range", contentRange);
   response.setHeader("Content-Length", contentLength, false);
-  response.setHeader("Content-Type", "video/ogg", false);
+  response.setHeader("Content-Type", type, false);
   response.setHeader("Accept-Ranges", "bytes", false);
   response.write(byterange, byterange.length);
   bis.close();
 }
--- a/dom/media/test/midflight-redirect.sjs
+++ b/dom/media/test/midflight-redirect.sjs
@@ -11,16 +11,17 @@ function parseQuery(query, key) {
 
 // Return the first few bytes in a short byte range response. When Firefox
 // requests subsequent bytes in a second range request, respond with a
 // redirect. Requests after the first redirected are serviced as expected.
 function handleRequest(request, response)
 {
   var query = request.queryString;
   var resource = parseQuery(query, "resource");
+  var type = parseQuery(query, "type") || "application/octet-stream";
   var redirected = parseQuery(query, "redirected") || false;
   var useCors = parseQuery(query, "cors") || false;
 
   var file = Components.classes["@mozilla.org/file/directory_service;1"].
                         getService(Components.interfaces.nsIProperties).
                         get("CurWorkD", Components.interfaces.nsIFile);
   var fis  = Components.classes['@mozilla.org/network/file-input-stream;1'].
                         createInstance(Components.interfaces.nsIFileInputStream);
@@ -56,16 +57,16 @@ function handleRequest(request, response
   byterange = bytes.substring(from, to + 1);
 
   let contentRange = "bytes "+ from +"-"+ to +"/"+ bytes.length;
   let contentLength = (to - from + 1).toString();
 
   response.setStatusLine(request.httpVersion, 206, "Partial Content");
   response.setHeader("Content-Range", contentRange);
   response.setHeader("Content-Length", contentLength, false);
-  response.setHeader("Content-Type", "video/ogg", false);
+  response.setHeader("Content-Type", type, false);
   response.setHeader("Accept-Ranges", "bytes", false);
   if (redirected && useCors) {
     response.setHeader("Access-Control-Allow-Origin", "*");
   }
   response.write(byterange, byterange.length);
   bis.close();
 }
--- a/dom/media/test/test_mediarecorder_principals.html
+++ b/dom/media/test/test_mediarecorder_principals.html
@@ -42,17 +42,17 @@ function testPrincipals(resource) {
     todo(false, "No types supported");
     return;
   }
   // First test: Load file from same-origin first, then get redirected to
   // another origin before attempting to record stream.
   let video = document.getElementById("v1");
   video.src =
       "http://mochi.test:8888/tests/dom/media/test/dynamic_redirect.sjs?key=v1_" +
-      key + "&res=" + resource.name;
+      key + "&res=" + resource.name + "&type=" + resource.type;
   return new Promise(resolve => video.onloadedmetadata = resolve).then(() => {
     video.load();
     video.play();
     interval = setInterval(() => info("video.currentTime = "+ video.currentTime), 1000);
 
     let msg = "mediaRecorder.start() must throw SecurityError";
     return new Promise(resolve => video.onplaying = resolve)
     .then(() => waitUntil(() => video.currentTime > resource.duration / 5))
@@ -63,17 +63,17 @@ function testPrincipals(resource) {
     .then(() => clearInterval(interval));
   })
   .then(() => {
     // Second test: Load file from same-origin first, but record ASAP, before
     // getting redirected to another origin.
     let video = document.getElementById("v2");
     video.src =
         "http://mochi.test:8888/tests/dom/media/test/dynamic_redirect.sjs?key=v2_" +
-        key + "&res=" + resource.name;
+        key + "&res=" + resource.name + "&type=" + resource.type;
     let rec, hasStopped, hasEnded = new Promise(r => video.onended = r);
     let data = [];
 
     let msgNoThrow = "mediaRecorder.start() should not throw here";
     let msgSecErr = "mediaRecorder.onerror must fire SecurityError";
     let msgOnStop = "mediaRecorder.onstop must also have fired";
     return new Promise(resolve => video.onloadedmetadata = resolve).then(() => {
       rec = new MediaRecorder(video.mozCaptureStreamUntilEnded());
--- a/dom/media/test/test_midflight_redirect_blocked.html
+++ b/dom/media/test/test_midflight_redirect_blocked.html
@@ -36,18 +36,19 @@
             removeNodeAndSource(element);
           }, false);
 
           element.addEventListener("error", ()=>{
             resolve(false);
             removeNodeAndSource(element);
           }, false);
 
-          let suffix = useCors ? "&cors" : "";
-          element.src = "midflight-redirect.sjs?resource=" + test.name + suffix;
+          element.src = "midflight-redirect.sjs?resource=" + test.name
+                      + (useCors ? "&cors" : "")
+                      + "&type=" + test.type;
           element.preload = "metadata";
           document.body.appendChild(element);
           element.load()
         });
       }
 
       let v = document.createElement("video");
       const testCases = gSmallTests.filter(t => v.canPlayType(t.type));