summaryrefslogtreecommitdiff
path: root/cli
diff options
context:
space:
mode:
authorMarcos Casagrande <marcoscvp90@gmail.com>2020-05-31 22:13:53 +0200
committerGitHub <noreply@github.com>2020-05-31 16:13:53 -0400
commit08552fc6b9a18c736b6fd3939d8e0b434f5b8302 (patch)
tree3ee875334bf4fd3e8a20a3eacc1f5a070193badb /cli
parentecb94c06e94c97ba07b804771f66c5e52c3d83ac (diff)
fix(fetch): network error on multiple redirects (#5985)
Diffstat (limited to 'cli')
-rw-r--r--cli/js/web/fetch.ts13
-rw-r--r--cli/tests/unit/fetch_test.ts5
2 files changed, 12 insertions, 6 deletions
diff --git a/cli/js/web/fetch.ts b/cli/js/web/fetch.ts
index a56ebe772..2f01e7ad7 100644
--- a/cli/js/web/fetch.ts
+++ b/cli/js/web/fetch.ts
@@ -288,6 +288,7 @@ export async function fetch(
}
}
+ let responseInit: ResponseInit = {};
while (remRedirectCount) {
const fetchResponse = await sendFetchReq(url, method, headers, body);
@@ -314,7 +315,7 @@ export async function fetch(
},
});
- let responseInit: ResponseInit = {
+ responseInit = {
status: fetchResponse.status,
statusText: fetchResponse.statusText,
headers: fetchResponse.headers,
@@ -374,6 +375,12 @@ export async function fetch(
return response;
}
}
- // Return a network error due to too many redirections
- throw notImplemented();
+
+ responseData.set(responseInit, {
+ type: "error",
+ redirected: false,
+ url: "",
+ });
+
+ return new Response(null, responseInit);
}
diff --git a/cli/tests/unit/fetch_test.ts b/cli/tests/unit/fetch_test.ts
index 6dfb23390..5fd1cc469 100644
--- a/cli/tests/unit/fetch_test.ts
+++ b/cli/tests/unit/fetch_test.ts
@@ -245,14 +245,13 @@ unitTest(
unitTest(
{
- // FIXME(bartlomieju):
- // The feature below is not implemented, but the test should work after implementation
- ignore: true,
perms: { net: true },
},
async function fetchWithInfRedirection(): Promise<void> {
const response = await fetch("http://localhost:4549/cli/tests"); // will redirect to the same place
assertEquals(response.status, 0); // network error
+ assertEquals(response.type, "error");
+ assertEquals(response.ok, false);
}
);