bytecodealliance / bytecodealliance/StarlingMonkey

Fetch not following redirects

Open
#297 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
288
Forks
57
PR merge metrics
No merged PRs in 30d

Description

Fetch doesn't follow redirect responses even when explicitly set to follow.

Given the following JS
```javascript
const STATUS_CODE = 302;
const EXPECTED_LOCATION = "https://example.com";
const URL = `https://httpbin.org/redirect-to?url=${EXPECTED_LOCATION}&status_code=${STATUS_CODE}`;

addEventListener('fetch', async e => {
let promise = fetch(URL, {
redirect: "follow",
})
.then((response) => {
if (response.status !== STATUS_CODE)
throw new Error(`Expected status code ${STATUS_CODE}, got ${response.status}`);
const location = response.headers.get("Location");
if (location !== EXPECTED_LOCATION)
throw new Error(`Expected location ${EXPECTED_LOCATION}, got ${location}`);
return response.text();
})
.then((text) => {
if (!text.includes("Example Domain")) {
throw new Error("Didn't redirect to example.com");
}
});
e.waitUntil(promise);
await promise;
e.respondWith(new Response(`Redirected successfully!`));
});
```

The component throws with the following output:
```shell
stderr [0] :: Warning: Promise passed to FetchEvent#waitUntil was rejected with error. Pending tasks after that error might not run. Error details:
stderr [0] :: Didn't redirect to example.com
stderr [0] :: Stack:
stderr [0] :: promise<@component.js:19:23
stderr [0] ::
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.