зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1675054 - Enable brotli encoding for trustworthy URLs, not just for https r=necko-reviewers,dragana
Differential Revision: https://phabricator.services.mozilla.com/D95855
This commit is contained in:
Родитель
7446e66b11
Коммит
b5b5de4192
|
@ -10781,6 +10781,13 @@
|
|||
value: false
|
||||
mirror: always
|
||||
|
||||
# When this pref is true, we will use the HTTPS acceptable content encoding
|
||||
# list for trustworthy domains such as http://localhost
|
||||
- name: network.http.encoding.trustworthy_is_https
|
||||
type: RelaxedAtomicBool
|
||||
value: true
|
||||
mirror: always
|
||||
|
||||
# Support http3 version1
|
||||
- name: network.http.http3.support_version1
|
||||
type: RelaxedAtomicBool
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "mozilla/dom/CanonicalBrowsingContext.h"
|
||||
#include "mozilla/dom/Document.h"
|
||||
#include "mozilla/dom/nsHTTPSOnlyUtils.h"
|
||||
#include "mozilla/dom/nsMixedContentBlocker.h"
|
||||
#include "mozilla/dom/Performance.h"
|
||||
#include "mozilla/dom/PerformanceStorage.h"
|
||||
#include "mozilla/dom/ProcessIsolation.h"
|
||||
|
@ -339,7 +340,10 @@ nsresult HttpBaseChannel::Init(nsIURI* aURI, uint32_t aCaps,
|
|||
// Construct connection info object
|
||||
nsAutoCString host;
|
||||
int32_t port = -1;
|
||||
bool isHTTPS = mURI->SchemeIs("https");
|
||||
bool isHTTPS =
|
||||
StaticPrefs::network_http_encoding_trustworthy_is_https()
|
||||
? nsMixedContentBlocker::IsPotentiallyTrustworthyLoopbackURL(mURI)
|
||||
: mURI->SchemeIs("https");
|
||||
|
||||
nsresult rv = mURI->GetAsciiHost(host);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
@ -1254,7 +1258,12 @@ HttpBaseChannel::DoApplyContentConversions(nsIStreamListener* aNextListener,
|
|||
break;
|
||||
}
|
||||
|
||||
if (gHttpHandler->IsAcceptableEncoding(val, mURI->SchemeIs("https"))) {
|
||||
bool isHTTPS =
|
||||
StaticPrefs::network_http_encoding_trustworthy_is_https()
|
||||
? nsMixedContentBlocker::IsPotentiallyTrustworthyLoopbackURL(mURI)
|
||||
: mURI->SchemeIs("https");
|
||||
|
||||
if (gHttpHandler->IsAcceptableEncoding(val, isHTTPS)) {
|
||||
RefPtr<nsHTTPCompressConv> converter = new nsHTTPCompressConv();
|
||||
nsAutoCString from(val);
|
||||
ToLowerCase(from);
|
||||
|
|
|
@ -17,28 +17,55 @@ XPCOMUtils.defineLazyGetter(this, "URL", function() {
|
|||
|
||||
var httpServer = null;
|
||||
|
||||
add_task(async function test() {
|
||||
add_task(async function check_brotli() {
|
||||
httpServer = new HttpServer();
|
||||
httpServer.registerPathHandler("/content", contentHandler);
|
||||
httpServer.start(-1);
|
||||
|
||||
async function test() {
|
||||
let chan = NetUtil.newChannel({ uri: URL, loadUsingSystemPrincipal: true });
|
||||
let [, buff] = await new Promise(resolve => {
|
||||
chan.asyncOpen(
|
||||
new ChannelListener(
|
||||
(req, buff) => {
|
||||
resolve([req, buff]);
|
||||
},
|
||||
null,
|
||||
CL_IGNORE_CL
|
||||
)
|
||||
);
|
||||
});
|
||||
return buff;
|
||||
}
|
||||
|
||||
Services.prefs.setBoolPref(
|
||||
"network.http.encoding.trustworthy_is_https",
|
||||
true
|
||||
);
|
||||
equal(
|
||||
await test(),
|
||||
"hello",
|
||||
"Should decode brotli when trustworthy_is_https=true"
|
||||
);
|
||||
Services.prefs.setBoolPref(
|
||||
"network.http.encoding.trustworthy_is_https",
|
||||
false
|
||||
);
|
||||
equal(
|
||||
await test(),
|
||||
"\x0b\x02\x80hello\x03",
|
||||
"Should not decode brotli when trustworthy_is_https=false"
|
||||
);
|
||||
Services.prefs.setCharPref(
|
||||
"network.http.accept-encoding",
|
||||
"gzip, deflate, br"
|
||||
);
|
||||
|
||||
let chan = NetUtil.newChannel({ uri: URL, loadUsingSystemPrincipal: true });
|
||||
let [, buff] = await new Promise(resolve => {
|
||||
chan.asyncOpen(
|
||||
new ChannelListener(
|
||||
(req, buff) => {
|
||||
resolve([req, buff]);
|
||||
},
|
||||
null,
|
||||
CL_IGNORE_CL
|
||||
)
|
||||
);
|
||||
});
|
||||
equal(buff, "hello");
|
||||
equal(
|
||||
await test(),
|
||||
"hello",
|
||||
"Should decode brotli if we set the HTTP accept encoding to include brotli"
|
||||
);
|
||||
Services.prefs.clearUserPref("network.http.accept-encoding");
|
||||
Services.prefs.clearUserPref("network.http.encoding.trustworthy_is_https");
|
||||
await httpServer.stop();
|
||||
});
|
||||
|
|
|
@ -181,6 +181,7 @@ function run_test() {
|
|||
prefs = Services.prefs;
|
||||
cePref = prefs.getCharPref("network.http.accept-encoding");
|
||||
prefs.setCharPref("network.http.accept-encoding", "gzip, deflate, br");
|
||||
prefs.setBoolPref("network.http.encoding.trustworthy_is_https", false);
|
||||
|
||||
httpserver.registerPathHandler("/test/cegzip1", handler);
|
||||
httpserver.registerPathHandler("/test/cegzip2", handler);
|
||||
|
|
Загрузка…
Ссылка в новой задаче