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

fix: do not stringify form data #475

Merged
merged 14 commits into from
Apr 8, 2022
Merged

fix: do not stringify form data #475

merged 14 commits into from
Apr 8, 2022

Conversation

sofisl
Copy link
Contributor

@sofisl sofisl commented Apr 5, 2022

Fixes #447

sofisl and others added 10 commits April 8, 2021 10:08

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil
        autosynth cannot find the source of changes triggered by earlier changes in this
        repository, or by version upgrades to tools such as linters.

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil
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

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil
@sofisl sofisl requested a review from a team as a code owner April 5, 2022 01:26
@product-auto-label product-auto-label bot added the size: s Pull request size is small. label Apr 5, 2022
sofisl added 2 commits April 4, 2022 18:26

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil
@sofisl sofisl changed the title Do not stringify form data build: do not stringify form data Apr 5, 2022
@ddelgrosso1
Copy link
Contributor

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';
Copy link
Contributor

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)) {
Copy link
Contributor

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 () => {
Copy link
Contributor

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').

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil
@sofisl sofisl requested a review from bcoe April 8, 2022 07:38
Copy link
Contributor

@bcoe bcoe left a 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.

@bcoe bcoe changed the title build: do not stringify form data fix: do not stringify form data Apr 8, 2022
@bcoe
Copy link
Contributor

bcoe commented Apr 8, 2022

I would call this a fix: when merging, so that we can put out a patch release for the user.

Verified

This commit was signed with the committer’s verified signature.
himdel Martin Hradil
@sofisl sofisl merged commit 17370dc into main Apr 8, 2022
@sofisl sofisl deleted the doNotStringifyFormData branch April 8, 2022 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: s Pull request size is small.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

formdata gets stringified
4 participants