3 const { HttpServer
} = ChromeUtils
.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
8 var path
= "/bug699001";
10 ChromeUtils
.defineLazyGetter(this, "URI", function () {
11 return "http://localhost:" + httpServer
.identity
.primaryPort
+ path
;
14 function make_channel(url
) {
15 return NetUtil
.newChannel({ uri
: url
, loadUsingSystemPrincipal
: true });
20 // The test loads a resource that expires in one year, has an etag and varies only by User-Agent
21 // First we load it, then check we load it only from the cache w/o even checking with the server
22 // Then we modify our User-Agent and try it again
23 // We have to get a new content (even though with the same etag) and again on next load only from
24 // cache w/o accessing the server
25 // Goal is to check we've updated User-Agent request header in cache after we've got 304 response
43 setUA("A different User Agent");
57 setUA("And another User Agent");
71 function handler(metadata
, response
) {
72 if (metadata
.hasHeader("If-None-Match")) {
73 response
.setStatusLine(metadata
.httpVersion
, 304, "Not modified");
75 response
.setStatusLine(metadata
.httpVersion
, 200, "OK");
76 response
.setHeader("Content-Type", "text/plain");
79 response
.bodyOutputStream
.write(body
, body
.length
);
84 response
.setHeader("Expires", getDateString(+1));
85 response
.setHeader("Cache-Control", "private");
86 response
.setHeader("Vary", "User-Agent");
87 response
.setHeader("ETag", "1234");
91 httpServer
= new HttpServer();
92 httpServer
.registerPathHandler(path
, handler
);
100 function nextTest() {
104 dump("Testing with User-Agent: " + getUA() + "\n");
105 var chan
= make_channel(URI
);
107 // Give the old channel a chance to close the cache entry first.
108 // XXX This is actually a race condition that might be considered a bug...
109 executeSoon(function () {
110 chan
.asyncOpen(new ChannelListener(checkAndShiftTest
, null));
114 function checkAndShiftTest(request
, response
) {
115 tests
[0].test(response
);
119 httpServer
.stop(tearDown
);
126 function tearDown() {
134 var httphandler
= Cc
["@mozilla.org/network/protocol;1?name=http"].getService(
135 Ci
.nsIHttpProtocolHandler
137 return httphandler
.userAgent
;
140 function setUA(value
) {
141 Services
.prefs
.setCharPref("general.useragent.override", value
);
144 function getDateString(yearDelta
) {
159 var days
= ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
163 days
[d
.getUTCDay()] +
167 months
[d
.getUTCMonth()] +
169 (d
.getUTCFullYear() + yearDelta
) +