diff --git a/devtools/client/netmonitor/src/utils/request-utils.js b/devtools/client/netmonitor/src/utils/request-utils.js index 564fdda28abe..7e5d45d56497 100644 --- a/devtools/client/netmonitor/src/utils/request-utils.js +++ b/devtools/client/netmonitor/src/utils/request-utils.js @@ -93,8 +93,8 @@ async function getFormDataSections( * @return {object} a headers object with updated content payload */ async function fetchHeaders(headers, getLongString) { - for (const { value } of headers.headers) { - headers.headers.value = await getLongString(value); + for (const header of headers.headers) { + header.value = await getLongString(header.value); } return headers; } diff --git a/devtools/client/netmonitor/test/xpcshell/test_request-utils-fetchHeaders.js b/devtools/client/netmonitor/test/xpcshell/test_request-utils-fetchHeaders.js new file mode 100644 index 000000000000..e34889c2498a --- /dev/null +++ b/devtools/client/netmonitor/test/xpcshell/test_request-utils-fetchHeaders.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { require } = ChromeUtils.importESModule( + "resource://devtools/shared/loader/Loader.sys.mjs" +); +const { + fetchHeaders, +} = require("resource://devtools/client/netmonitor/src/utils/request-utils.js"); + +add_task(async function test_fetchHeaders_resolves_long_string_values() { + const longCookieValue = "a=1; ".repeat(2001); + + const mockLongStringGrip = { + type: "longString", + initial: longCookieValue.substring(0, 1000), + length: longCookieValue.length, + }; + + const headers = { + headers: [ + { name: "User-Agent", value: "Mozilla/5.0" }, + { name: "Cookie", value: mockLongStringGrip }, + ], + headersSize: 12345, + }; + + async function mockGetLongString(value) { + if (typeof value === "object" && value.type === "longString") { + return longCookieValue; + } + return value; + } + + const result = await fetchHeaders(headers, mockGetLongString); + + equal( + result.headers[0].value, + "Mozilla/5.0", + "Short string header value is preserved" + ); + equal( + typeof result.headers[1].value, + "string", + "Long string Cookie header value is resolved to a string" + ); + equal( + result.headers[1].value, + longCookieValue, + "Long string Cookie header value is correctly resolved to its full content" + ); +}); diff --git a/devtools/client/netmonitor/test/xpcshell/xpcshell.toml b/devtools/client/netmonitor/test/xpcshell/xpcshell.toml index 087f3d10a162..6630349a5611 100644 --- a/devtools/client/netmonitor/test/xpcshell/xpcshell.toml +++ b/devtools/client/netmonitor/test/xpcshell/xpcshell.toml @@ -8,6 +8,8 @@ run-if = [ ["test_doc-utils.js"] +["test_request-utils-fetchHeaders.js"] + ["test_request-utils-fetchNetworkUpdatePacket.js"] ["test_request-utils-js-getFormattedProtocol.js"]