Skip to content
This repository was archived by the owner on Jan 3, 2026. It is now read-only.
This repository was archived by the owner on Jan 3, 2026. It is now read-only.

Forced 'Content-Type' header #156

@dragoncodes

Description

@dragoncodes

Gaxios rewrites the Content-Type header when the payload is of type 'object' in validateOpts:

    if (opts.data) {
      if (this.isReadableStream(opts.data)) {
        opts.body = opts.data;
      } else if (typeof opts.data === 'object') { // <-- Here
        opts.body = JSON.stringify(opts.data);
        opts.headers['Content-Type'] = 'application/json';
      } else {
        opts.body = opts.data;
      }
    }

I am currently updating to the google publisher v3 API (NodeJS) and I've hit a snag.
I am reading and passing the apk data as follows:

const apk = fs.readFileSync(apkFilePath);

this.publisher.edits.apks.upload({
           editId,
           packageName,
           media: {
               mimeType: 'application/vnd.android.package-archive',
               body: apk
            }
}, (err, res) => {});

In this case, I am explicitly specifying the mimeType to the one required by the upload API, apk variable is of type Buffer, but a typeof check returns 'object'. The upload API then returns

Media type 'application/json' is not supported. Valid media types: [application/octet-stream, application/vnd.android.package-archive] 

I'm not sure why there's a need to force the header and serialization when the user has explicitly set them, maybe I am missing something though 🤔

Metadata

Metadata

Labels

type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions