1 // This test exists mostly as documentation that
2 // Firefox can load brotli files over HTTP if we set the proper pref.
6 function contentHandler(metadata
, response
) {
7 response
.setHeader("Content-Type", "text/plain", false);
8 response
.setHeader("Content-Encoding", "br", false);
9 response
.write("\x0b\x02\x80hello\x03");
12 const { HttpServer
} = ChromeUtils
.importESModule(
13 "resource://testing-common/httpd.sys.mjs"
16 ChromeUtils
.defineLazyGetter(this, "URL", function () {
17 return "http://localhost:" + httpServer
.identity
.primaryPort
+ "/content";
20 var httpServer
= null;
22 add_task(async
function check_brotli() {
23 httpServer
= new HttpServer();
24 httpServer
.registerPathHandler("/content", contentHandler
);
27 async
function test() {
28 let chan
= NetUtil
.newChannel({ uri
: URL
, loadUsingSystemPrincipal
: true });
29 let [, buff
] = await
new Promise(resolve
=> {
33 resolve([req
, buff1
]);
43 Services
.prefs
.setBoolPref(
44 "network.http.encoding.trustworthy_is_https",
50 "Should decode brotli when trustworthy_is_https=true"
52 Services
.prefs
.setBoolPref(
53 "network.http.encoding.trustworthy_is_https",
58 "\x0b\x02\x80hello\x03",
59 "Should not decode brotli when trustworthy_is_https=false"
61 Services
.prefs
.setCharPref(
62 "network.http.accept-encoding",
68 "Should decode brotli if we set the HTTP accept encoding to include brotli"
70 Services
.prefs
.clearUserPref("network.http.accept-encoding");
71 Services
.prefs
.clearUserPref("network.http.encoding.trustworthy_is_https");
72 await httpServer
.stop();
75 // Make sure we still decode brotli on HTTPS
76 // Node server doesn't work on Android yet.
78 { skip_if
: () => AppConstants
.platform
== "android" },
79 async
function check_https() {
80 Services
.prefs
.setBoolPref(
81 "network.http.encoding.trustworthy_is_https",
84 let certdb
= Cc
["@mozilla.org/security/x509certdb;1"].getService(
87 addCertFromFile(certdb
, "http2-ca.pem", "CTu,u,u");
89 let server
= new NodeHTTPSServer();
91 registerCleanupFunction(async () => {
94 await server
.registerPathHandler("/brotli", (req
, resp
) => {
95 resp
.setHeader("Content-Type", "text/plain");
96 resp
.setHeader("Content-Encoding", "br");
97 let output
= "\x0b\x02\x80hello\x03";
99 resp
.end(output
, "binary");
102 Services
.prefs
.getCharPref("network.http.accept-encoding.secure"),
103 "gzip, deflate, br, zstd"
105 let { req
, buff
} = await
new Promise(resolve
=> {
106 let chan
= NetUtil
.newChannel({
107 uri
: `${server.origin()}/brotli`,
108 loadUsingSystemPrincipal
: true,
112 (req1
, buff1
) => resolve({ req
: req1
, buff
: buff1
}),
118 equal(req
.status
, Cr
.NS_OK
);
119 equal(req
.QueryInterface(Ci
.nsIHttpChannel
).responseStatus
, 200);
120 equal(buff
, "hello");