Bug 1443942 - Make redirect SJS' serve with headers to prevent Necko caching. r?jya draft
authorChris Pearce <cpearce@mozilla.com>
Wed, 28 Mar 2018 16:55:46 +1300
changeset 779058 cd981c7dd553cc5099c14731722396507f688257
parent 779057 27dd68c9a1f607f85ccece081ad54a581d00b2e9
child 779059 98de0bf9ad6b02daffb7890cb2e64145a16d388a
push id105646
push userbmo:cpearce@mozilla.com
push dateSun, 08 Apr 2018 22:04:39 +0000
reviewersjya
bugs1443942
milestone61.0a1
Bug 1443942 - Make redirect SJS' serve with headers to prevent Necko caching. r?jya Try to prevent Necko from caching the results of our SJS media responses, as some of the test that use it rely on the server being hit and serving a redirect. Sometimes the tests which rely on hitting a redirect in an SJS where timing out without this, as Necko would cache the response and not hit the server, and so not hit the redirect. Also include a noise parameter to increase the likelihood that the URL is unique, to further reduce the chance that Necko caches the result. MozReview-Commit-ID: 3cLEiDoh4HG
dom/media/test/dynamic_redirect.sjs
dom/media/test/midflight-redirect.sjs
dom/media/test/test_midflight_redirect_blocked.html
--- a/dom/media/test/dynamic_redirect.sjs
+++ b/dom/media/test/dynamic_redirect.sjs
@@ -58,11 +58,12 @@ function handleRequest(request, response
   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", type, false);
   response.setHeader("Accept-Ranges", "bytes", false);
+  response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
   response.write(byterange, byterange.length);
   bis.close();
 }
--- a/dom/media/test/midflight-redirect.sjs
+++ b/dom/media/test/midflight-redirect.sjs
@@ -59,14 +59,15 @@ function handleRequest(request, response
   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", type, false);
   response.setHeader("Accept-Ranges", "bytes", false);
+  response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate");
   if (redirected && useCors) {
     response.setHeader("Access-Control-Allow-Origin", "*");
   }
   response.write(byterange, byterange.length);
   bis.close();
 }
--- a/dom/media/test/test_midflight_redirect_blocked.html
+++ b/dom/media/test/test_midflight_redirect_blocked.html
@@ -36,19 +36,21 @@
             removeNodeAndSource(element);
           }, false);
 
           element.addEventListener("error", ()=>{
             resolve(false);
             removeNodeAndSource(element);
           }, false);
 
+          var noise = Math.floor(Math.random() * 100000000);
           element.src = "midflight-redirect.sjs?resource=" + test.name
                       + (useCors ? "&cors" : "")
-                      + "&type=" + test.type;
+                      + "&type=" + test.type
+                      + "&noise=" + noise;
           element.preload = "metadata";
           document.body.appendChild(element);
           element.load()
         });
       }
 
       let v = document.createElement("video");
       const testCases = gSmallTests.filter(t => v.canPlayType(t.type));