-
Notifications
You must be signed in to change notification settings - Fork 62
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: do not stringify form data #475
Conversation
autosynth cannot find the source of changes triggered by earlier changes in this repository, or by version upgrades to tools such as linters.
Source-Author: Benjamin E. Coe <bencoe@google.com> Source-Date: Tue May 11 17:35:28 2021 -0700 Source-Repo: googleapis/synthtool Source-Sha: b891fb474173f810051a7fdb0d66915e0a9bc82f Source-Link: googleapis/synthtool@b891fb4
The changes make sense to me. With this update is it safe to say that gaxios would now be able to support multipart requests? |
src/gaxios.ts
Outdated
@@ -18,6 +18,7 @@ import nodeFetch from 'node-fetch'; | |||
import qs from 'querystring'; | |||
import isStream from 'is-stream'; | |||
import {URL} from 'url'; | |||
import FormData from '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.
form-data
is a shim in the npm ecosystem that looks like the FormData
class (which exists in browser environments).
We shouldn't actually add this to our library.
src/gaxios.ts
Outdated
@@ -252,7 +253,7 @@ export class Gaxios { | |||
'application/x-www-form-urlencoded' | |||
) { | |||
opts.body = opts.paramsSerializer(opts.data); | |||
} else { | |||
} else if (!(opts.data instanceof FormData)) { |
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.
instead of adding the form-data
dependency, we can do:
const isFormData = typeof FormData === 'undefined' ? false : opts?.data instanceof FormData
if (opts.data && !isFormData) {
`...`.
}
The reason for moving the logic to the top like this is that I believe we also want to avoid calling:
opts.body = opts.paramsSerializer(opts.data);
@@ -381,6 +382,21 @@ describe('🥁 configuration options', () => { | |||
assert.deepStrictEqual(res.config.data, body); | |||
}); | |||
|
|||
it('should not stringify the data if it is appended by a form', async () => { |
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.
To have a test you could continue installing form-data
as a development dependency, rather than a dependency.
And then you could perhaps do, global.FormData = require('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.
LGTM, I think it's great that you added a test even though it's a bit of a nuisance to do so.
I would call this a |
Fixes #447