fix(fetch): network error on multiple redirects (#5985)

This commit is contained in:
Marcos Casagrande 2020-05-31 22:13:53 +02:00 committed by GitHub
parent ecb94c06e9
commit 08552fc6b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 7 deletions

View file

@ -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);
}

View file

@ -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);
}
);

View file

@ -363,7 +363,7 @@ def start(s):
def spawn():
servers = (server(), redirect_server(), another_redirect_server(),
double_redirects_server(), https_server(),
absolute_redirect_server())
absolute_redirect_server(), inf_redirects_server())
# In order to wait for each of the servers to be ready, we try connecting to
# them with a tcp socket.
for running_server in servers: