diff --git a/toolkit/components/extensions/parent/ext-downloads.js b/toolkit/components/extensions/parent/ext-downloads.js index 28aedf887b03b..135eda51ce968 100644 --- a/toolkit/components/extensions/parent/ext-downloads.js +++ b/toolkit/components/extensions/parent/ext-downloads.js @@ -644,30 +644,42 @@ this.downloads = class extends ExtensionAPI { } function allowHttpStatus(download, status) { - if (status < 400) { - return true; - } - const item = DownloadMap.byDownload.get(download); if (item === null) { return true; } - if (status === 404) { - item.error = "SERVER_BAD_CONTENT"; - return false; - } - if (status === 403) { - item.error = "SERVER_FORBIDDEN"; - return false; + let error = null; + switch (status) { + case 204: // No Content + case 205: // Reset Content + case 404: // Not Found + error = "SERVER_BAD_CONTENT"; + break; + + case 403: // Forbidden + error = "SERVER_FORBIDDEN"; + break; + + case 402: // Unauthorized + case 407: // Proxy authentication required + error = "SERVER_UNAUTHORIZED"; + break; + + default: + if (status >= 400) { + error = "SERVER_FAILED"; + } + break; } - // Unauthorized and proxy authorization required - if (status === 402 || status == 407) { - item.error = "SERVER_UNAUTHORIZED"; + + if (error) { + item.error = error; return false; } - item.error = "SERVER_FAILED"; - return false; + + // No error, ergo allow the request. + return true; } async function createTarget(downloadsDir) { diff --git a/toolkit/components/extensions/test/xpcshell/test_ext_downloads_download.js b/toolkit/components/extensions/test/xpcshell/test_ext_downloads_download.js index f55fa51904a28..986aa73d3c896 100644 --- a/toolkit/components/extensions/test/xpcshell/test_ext_downloads_download.js +++ b/toolkit/components/extensions/test/xpcshell/test_ext_downloads_download.js @@ -467,7 +467,13 @@ add_task(async function test_download_http_errors() { return extension.awaitMessage("done"); } - let res = await download(404); + let res = await download(204); // No Content + equal(res, "SERVER_BAD_CONTENT", "error is correct"); + + res = await download(204); // Reset Content + equal(res, "SERVER_BAD_CONTENT", "error is correct"); + + res = await download(404); equal(res, "SERVER_BAD_CONTENT", "error is correct"); res = await download(403); @@ -476,7 +482,7 @@ add_task(async function test_download_http_errors() { res = await download(402); equal(res, "SERVER_UNAUTHORIZED", "error is correct"); - res = await download(407); + res = await download(407); // Proxy authentication required equal(res, "SERVER_UNAUTHORIZED", "error is correct"); res = await download(504);