Skip to content

Commit

Permalink
Bug 1579850: Treat HTTP 204 and HTTP 205 as SERVER_BAD_CONTENT r=robwu
Browse files Browse the repository at this point in the history
Differential Revision: https://phabricator.services.mozilla.com/D45185

--HG--
extra : moz-landing-system : lando
  • Loading branch information
nmaier committed Sep 9, 2019
1 parent f5d787c commit ff8c88f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 18 deletions.
44 changes: 28 additions & 16 deletions toolkit/components/extensions/parent/ext-downloads.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit ff8c88f

Please sign in to comment.