commit fba50614bc3690f892513791c3f891b0e786234a
parent d835cf9f440ec066f7c9ecb6cef034d7f46d3a50
Author: Randell Jesup <rjesup@mozilla.com>
Date: Wed, 26 Nov 2025 19:17:52 +0000
Bug 2002034: When matching for CompressionDictionaries pass the cache entry URI to URLPattern r=necko-reviewers,valentin,kershaw
In the spec, section 2.2.2 step 2
Differential Revision: https://phabricator.services.mozilla.com/D273938
Diffstat:
3 files changed, 46 insertions(+), 11 deletions(-)
diff --git a/netwerk/cache2/Dictionary.cpp b/netwerk/cache2/Dictionary.cpp
@@ -169,7 +169,7 @@ bool DictionaryCacheEntry::Match(const nsACString& aFilePath,
aType)) != mMatchDest.NoIndex) {
UrlpPattern pattern;
UrlpOptions options;
- const nsCString base("https://foo.com/"_ns);
+ const nsCString base(mURI);
if (!urlp_parse_pattern_from_string(&mPattern, &base, options,
&pattern)) {
DICTIONARY_LOG(
@@ -1071,7 +1071,7 @@ void DictionaryCache::GetDictionaryFor(
nsCString path;
RefPtr<DictionaryCacheEntry> result;
- aURI->GetPathQueryRef(path);
+ aURI->GetSpec(path);
DICTIONARY_LOG(("GetDictionaryFor(%s %s)", prepath.get(), path.get()));
result = existing.Data()->Match(path, aType);
diff --git a/netwerk/test/unit/test_dictionary_compression_dcb.js b/netwerk/test/unit/test_dictionary_compression_dcb.js
@@ -444,7 +444,7 @@ async function setupDicts() {
let dictKey = dictKeys[i];
let url = `${server.origin()}${path}`;
dump(
- `registering dictionary ${path} for match patter ${DCB_TEST_DICTIONARIES[dictKey].patterh}\n`
+ `registering dictionary ${path} for match pattern ${DCB_TEST_DICTIONARIES[dictKey].pattern}\n`
);
let chan = makeChan(url);
@@ -496,9 +496,9 @@ add_task(async function test_basic_dcb_compression() {
// Setup DCB endpoint for HTML content
let dict = DCB_TEST_DICTIONARIES.html_common;
let content = DCB_TEST_CONTENT.html_page;
- await registerDCBEndpoint(server, "/test.html", dict, content, true);
+ await registerDCBEndpoint(server, "/dict/test.html", dict, content, true);
- let url = `${server.origin()}/test.html`;
+ let url = `${server.origin()}/dict/test.html`;
let chan = makeChan(url);
let [request, data] = await channelOpenPromise(chan);
@@ -511,6 +511,37 @@ add_task(async function test_basic_dcb_compression() {
Assert.ok(usedDCB, "DCB compression should be used");
});
+// Test correct use of URLPattern baseurl
+add_task(async function test_baseurl() {
+ dump("**** test_baseurl\n");
+ requestLog = [];
+ await sync_to_server();
+
+ // Setup DCB endpoint for HTML content
+ let dict = DCB_TEST_DICTIONARIES.html_common;
+ let content = DCB_TEST_CONTENT.html_page;
+ await registerDCBEndpoint(server, "/test.html", dict, content, true);
+
+ let url = `${server.origin()}/test.html`;
+ let chan = makeChan(url);
+ let [request, data] = await channelOpenPromise(chan);
+
+ Assert.greater(
+ data.length,
+ 0,
+ "Should still receive content without dictionary in use"
+ );
+ // Check if DCB compression was used (should be false)
+ Assert.ok(
+ !verifyDCBResponse(
+ request.QueryInterface(Ci.nsIHttpChannel),
+ data,
+ DCB_TEST_DICTIONARIES.html_common_no_dictionary
+ ),
+ "DCB compression should not be used with the wrong path"
+ );
+});
+
// Test correct dictionary selection for dcb compression
add_task(async function test_dcb_dictionary_selection() {
requestLog = [];
@@ -525,7 +556,7 @@ add_task(async function test_dcb_dictionary_selection() {
// Register endpoints that should match different dictionaries
await registerDCBEndpoint(
server,
- "/specific-test.html",
+ "/dict/specific-test.html",
htmlDict,
DCB_TEST_CONTENT.html_page,
true
@@ -539,7 +570,7 @@ add_task(async function test_dcb_dictionary_selection() {
);
// Test HTML dictionary selection
- let htmlUrl = `${server.origin()}/specific-test.html`;
+ let htmlUrl = `${server.origin()}/dict/specific-test.html`;
let htmlChan = makeChan(htmlUrl);
let [, htmlData] = await channelOpenPromise(htmlChan);
@@ -552,7 +583,7 @@ add_task(async function test_dcb_dictionary_selection() {
// Check if correct dictionary was used
await sync_from_server();
let htmlLogEntry = requestLog.find(
- entry => entry.path === "/specific-test.html"
+ entry => entry.path === "/dict/specific-test.html"
);
Assert.ok(
htmlLogEntry && htmlLogEntry.hasAvailableDict,
@@ -715,7 +746,7 @@ add_task(async function test_dcb_compression_after_cache_eviction() {
let dict = DCB_TEST_DICTIONARIES.html_common;
let dict2 = DCB_TEST_DICTIONARIES.html_common_no_dictionary;
let testContent = DCB_TEST_CONTENT.html_page;
- let testPath = "/cache-eviction-test.html";
+ let testPath = "/dict/cache-eviction-test.html";
let dictUrl = `${server.origin()}/dict/html`;
let contentUrl = `${server.origin()}${testPath}`;
@@ -807,9 +838,9 @@ add_task(async function test_dcb_with_http_redirect() {
let dict = DCB_TEST_DICTIONARIES.html_common;
let content = DCB_TEST_CONTENT.html_page;
- await registerDCBEndpoint(server, "/test.html", dict, content, true);
+ await registerDCBEndpoint(server, "/dict/test.html", dict, content, true);
let originalPath = "/redirect/original";
- let finalPath = "/test.html";
+ let finalPath = "/dict/test.html";
let originalUrl = `${server.origin()}${originalPath}`;
let finalUrl = `${server.origin()}${finalPath}`;
diff --git a/netwerk/test/unit/xpcshell.toml b/netwerk/test/unit/xpcshell.toml
@@ -485,6 +485,7 @@ run-sequentially = ["true"] # httpd server
run-sequentially = ["true"] # httpd server
["test_cache2_compression_dictionary.js"]
+run-sequentially = ["true"]
["test_cache2_nostore.js"]
@@ -593,10 +594,13 @@ prefs = ["content.cors.use_triggering_principal=true"] # See bug 1982916.
["test_defaultURI.js"]
["test_dictionary_compression_dcb.js"]
+run-sequentially = ["true"]
["test_dictionary_retrieval.js"]
+run-sequentially = ["true"]
["test_dictionary_storage.js"]
+run-sequentially = ["true"]
["test_dns_by_type_resolve.js"]