-
Notifications
You must be signed in to change notification settings - Fork 548
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
FormData body throws if request is redirected #3803
Comments
What version of undici are you using? |
I'm pretty sure it's the latest because I had just upgraded but I'll let you know asap |
This is a bug in v6 that is patched in v7 (7.0.0-alpha.3). The fix will have to be backported. |
I see, I'll try updating to alpha, thanks! |
@KhafraDev do you know which PR? |
It seems that using the alpha the redirect is not followed at all? Not sure if I'm doing something wrong but I'll try to send an example |
import { request } from "undici";
const data = await request("http://github.com", { maxRedirections: 8 });
console.log(data.statusCode, data.headers.location); This logs Unless I missed a breaking change in the 7.0 Edit: Manually using the RedirectHandler works |
So, as I said above, |
|
The patch seems not to work with h2: import { Agent, FormData, interceptors, request } from "undici";
const body = new FormData();
body.append("hello", "world");
await request("http://github.com", {
dispatcher: new Agent({ allowH2: true }).compose(
interceptors.redirect({ maxRedirections: 1 }),
),
body,
method: "POST",
}); throw new ERR_INVALID_ARG_TYPE(
^
TypeError [ERR_INVALID_ARG_TYPE]: The "chunk" argument must be of type string or an instance of Buffer, TypedArray, or DataView. Received an instance of Array
at _write (node:internal/streams/writable:482:13)
at Writable.write (node:internal/streams/writable:510:10)
at writeIterable (D:\-\node_modules\undici\lib\dispatcher\client-h2.js:740:28) {
code: 'ERR_INVALID_ARG_TYPE'
} |
Bug Description
When sending a
FormData
as body withrequest
orstream
, the request fails if redirected with the followingTypeError
:The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received an instance of Array
Reproducible By
In the following example a
POST
request is made tohttp://github.com
, which automatically redirects tohttps://github.com
. The issue is reproducible with any other url that triggers a redirect.Expected Behavior
Not sure about the specs but the body should be either redirected or discarded based on the redirect type, without any errors.
Logs & Screenshots
Environment
Windows 11 Home, Node v22.11.0
Additional context
Tested with various redirect urls and the issue is always reproducible
The text was updated successfully, but these errors were encountered: