-
-
Notifications
You must be signed in to change notification settings - Fork 919
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
Detect formdata body and set content-type header. #220
Conversation
if (isPlainObj(body)) { | ||
if (isStream(body) && typeof body.getBoundary === 'function') { | ||
// Special case for https://github.com/form-data/form-data | ||
opts.headers['content-type'] = opts.headers['content-type'] || 'multipart/form-data; boundary=' + body.getBoundary(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
content-type
is not the only header, that can be returned from getHeaders
function. This line should contain call to getHeaders
and assign user supplied headers over it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`multipart/form-data; boundary=${body.getBoundary()}`;
The test should send a request and check that correct headers were actually sent. See other tests for how to do it. |
ping @DylanPiercey :) |
@sindresorhus sorry forgot about this one, I'll try to get to it later today. @floatdrop currently formdata getHeaders only returns content-type and that will not change so I figured this was the most appropriate api. Especially since in @2.0 the getHeaders function may have a deprecation warning. |
@sindresorhus does that look better? (Added some tests). |
Let me know if anything else is needed @sindresorhus 😀. |
LGTM when #220 (comment) is fixed. @floatdrop ? |
Okay then.
Lgtm. Waiting for #220 (comment) |
Actually, I'll just fix it when merging. Thanks @DylanPiercey :) |
This PR adds a check for Form-Data which makes it easier for users to submit form data bodies (no longer have to manually get headers from form-data).
This is similar to node-fetch/node-fetch#31, the idea is just to make it easier on end users since Form-Data is commonly used throughout the community. It will also make isomorphic code easier in the future with isomorphic-form-data.
I realize this is missing a new test, I wasn't sure what the best way to go about it was.
If I got some direction I could go ahead with tests or someone else could take over from here.