Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undici.fetch fails (terminates) on 3XX with redirect: "manual" #1622

Closed
AlttiRi opened this issue Aug 29, 2022 · 2 comments
Closed

undici.fetch fails (terminates) on 3XX with redirect: "manual" #1622

AlttiRi opened this issue Aug 29, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@AlttiRi
Copy link

AlttiRi commented Aug 29, 2022

Bug Description

undici.fetch fails on 301 "Moved Permanently" (and similar redirects) with redirect: "manual"

Reproducible By

import {fetch} from "undici";
// import fetch from "node-fetch"; // works fine

const url = "https://tinyurl.com/2af6by3e"; // 301 Moved Permanently
// const url = "https://tinyurl.com/y3rv756e"; // 302 Found

const resp = await fetch(url, {
    redirect: "manual"
});

console.log(resp.status, resp.statusText, resp.redirected);
console.log(resp.url);
console.log(resp.headers.get("location"));
console.log(resp);

const text = await resp.text();
console.log("---");
console.log(text);
console.log("---");

Expected Behavior

301 Moved Permanently false
https://tinyurl.com/2af6by3e
https://github.com/nodejs/undici/issues/1622
Response {
...
}
---
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='https://github.com/nodejs/undici/issues/1622'" />

        <title>Redirecting to https://github.com/nodejs/undici/issues/1622</title>
    </head>
    <body>
        Redirecting to <a href="https://github.com/nodejs/undici/issues/1622">https://github.com/nodejs/undici/issues/1622</a>.
    </body>
</html>
---

Result

301 Moved Permanently false
https://tinyurl.com/2af6by3e
https://github.com/nodejs/undici/issues/1622
Response {
...
}

TypeError: terminated
at Fetch.onAborted (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:1890:49)
at Fetch.emit (node:events:513:28)
at Fetch.terminate (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:83:10)
at Object.onError (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:2027:34)
at Request.onError (C:\Dev\downloader\node_modules\undici\lib\core\request.js:265:27)
at errorRequest (C:\Dev\downloader\node_modules\undici\lib\client.js:1722:13)
at Object.abort (C:\Dev\downloader\node_modules\undici\lib\client.js:1335:7)
at Object.destroy (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:1553:21)
at httpFetch (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:1051:39)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    [cause]: DOMException [AbortError]: The operation was aborted.
        at new DOMException (node:internal/per_context/domexception:53:5)
    at Object.destroy (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:1553:29)
    at httpFetch (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:1051:39)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async schemeFetch (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:875:14)
    at async C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:570:16
    at async mainFetch (C:\Dev\downloader\node_modules\undici\lib\fetch\index.js:554:16)
}

Node.js v18.7.0

Environment

  • "undici": "5.10.0"
@AlttiRi AlttiRi added the bug Something isn't working label Aug 29, 2022
@KhafraDev
Copy link
Member

See #1618

@KhafraDev
Copy link
Member

Fixed in #1627

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants