-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
fix: multipart/form-data body interpolation #3142
fix: multipart/form-data body interpolation #3142
Conversation
@Its-treason Can you review this if you have some time over the weekend? |
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.
I added some notes. But feature itself seems good.
@@ -195,6 +181,14 @@ const runSingleRequest = async function ( | |||
request.data = qs.stringify(request.data); | |||
} | |||
|
|||
if (request?.headers?.['content-type'] === 'multipart/form-data') { |
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.
These two if-statements can be merged.
// reference: https://github.com/axios/axios/issues/1006#issuecomment-320165427 | ||
const form = new FormData(); | ||
forOwn(datas, (value, key) => { | ||
if (typeof value == 'object') { |
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.
I would personally invert the if
to: typeof value === 'string'
and return after form.append
like this:
if (typeof data === 'string') {
form.append(key, value);
return;
}
// Code for file here.
To make the code more readable
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.
makes sense, will update the logic
@@ -15,7 +15,7 @@ | |||
"bypassProxy": "" | |||
}, | |||
"scripts": { | |||
"moduleWhitelist": ["crypto", "buffer"], | |||
"moduleWhitelist": ["crypto", "buffer", "form-data"], |
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.
We could add form-data
to the default libraries.
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.
since form-data
dep needs to be added to both vm2 and quickjs, i'l create a seperate pr for just that
Merged. Thanks @lohxt1 for working on this! |
changes:
~ the
formData body
will be available in json format during the pre-request script (req.getBody()
).json body
is interpolated after the pre-request step, and theformData body
is then constructed from the json data.~ if a constructed
formData body
is directly set in the pre-request script, the interpolation and the construction offormData body
are skipped.