1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 // This test file makes sure that we can decode brotli files when the
6 // Content-Type header is missing (Bug 1715401)
10 function emptyBrotli(metadata, response) {
11 response.setHeader("Content-Encoding", "br", false);
12 response.write("\x01\x03\x06\x03");
15 function largeEmptyBrotli(metadata, response) {
16 response.setHeader("Content-Encoding", "br", false);
17 response.write("\x01\x03" + "\x06".repeat(600) + "\x03");
20 const { HttpServer } = ChromeUtils.importESModule(
21 "resource://testing-common/httpd.sys.mjs"
24 ChromeUtils.defineLazyGetter(this, "URL_EMPTY_BROTLI", function () {
26 "http://localhost:" + httpServer.identity.primaryPort + "/empty-brotli"
30 ChromeUtils.defineLazyGetter(this, "URL_LARGE_EMPTY_BROTLI", function () {
33 httpServer.identity.primaryPort +
38 var httpServer = null;
40 add_task(async function check_brotli() {
41 httpServer = new HttpServer();
42 httpServer.registerPathHandler("/empty-brotli", emptyBrotli);
43 httpServer.registerPathHandler("/large-empty-brotli", largeEmptyBrotli);
46 async function test(url) {
47 let chan = NetUtil.newChannel({ uri: url, loadUsingSystemPrincipal: true });
48 let [, response] = await new Promise(resolve => {
62 await test(URL_EMPTY_BROTLI),
64 "Should decode brotli even when brotli output is empty"
67 await test(URL_LARGE_EMPTY_BROTLI),
69 "Should decode brotli even when the nsUnknownDecoder can't get any decoded output"
71 Services.prefs.clearUserPref("network.http.accept-encoding");
72 Services.prefs.clearUserPref("network.http.encoding.trustworthy_is_https");
73 await httpServer.stop();