3 const { HttpServer
} = ChromeUtils
.importESModule(
4 "resource://testing-common/httpd.sys.mjs"
7 var httpserver
= new HttpServer();
9 var responseBody
= [0x0b, 0x02, 0x80, 0x74, 0x65, 0x73, 0x74, 0x0a, 0x03];
11 var testUrl
= "/test/brotli";
13 function setupChannel() {
14 return NetUtil
.newChannel({
15 uri
: "http://localhost:" + httpserver
.identity
.primaryPort
+ testUrl
,
16 loadUsingSystemPrincipal
: true,
20 function Listener() {}
22 Listener
.prototype = {
25 QueryInterface
: ChromeUtils
.generateQI([
30 onStartRequest(request
) {
31 Assert
.equal(request
.status
, Cr
.NS_OK
);
35 onDataAvailable(request
, stream
, offset
, cnt
) {
37 this._buffer
= this._buffer
.concat(read_stream(stream
, cnt
));
39 request
.QueryInterface(Ci
.nsICachingChannel
);
40 if (!request
.isFromCache()) {
41 do_throw("Response is not from the cache");
44 request
.cancel(Cr
.NS_ERROR_ABORT
);
50 Assert
.equal(this._buffer
.length
, responseLen
);
53 var channel
= setupChannel();
54 channel
.loadFlags
= Ci
.nsIRequest
.VALIDATE_NEVER
;
55 channel
.asyncOpen(new Listener());
57 httpserver
.stop(do_test_finished
);
58 prefs
.setCharPref("network.http.accept-encoding", cePref
);
68 prefs
= Services
.prefs
;
69 cePref
= prefs
.getCharPref("network.http.accept-encoding");
70 prefs
.setCharPref("network.http.accept-encoding", "gzip, deflate, br");
72 // Disable rcwn to make cache behavior deterministic.
73 prefs
.setBoolPref("network.http.rcwn.enabled", false);
75 httpserver
.registerPathHandler(testUrl
, handler
);
78 var channel
= setupChannel();
79 channel
.asyncOpen(new Listener());
84 function handler(metadata
, response
) {
85 Assert
.equal(pass
, 0); // the second response must be server from the cache
87 response
.setStatusLine(metadata
.httpVersion
, 200, "OK");
88 response
.setHeader("Content-Type", "text/plain", false);
89 response
.setHeader("Content-Encoding", "br", false);
90 response
.setHeader("Content-Length", "" + responseBody
.length
, false);
92 var bos
= Cc
["@mozilla.org/binaryoutputstream;1"].createInstance(
93 Ci
.nsIBinaryOutputStream
95 bos
.setOutputStream(response
.bodyOutputStream
);
97 response
.processAsync();
98 bos
.writeByteArray(responseBody
);