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

[WIP] attempt upgrade to axios 1.x #213

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: node_js

node_js:
- 12
- 14
- 16

cache:
npm: false
Expand Down
15 changes: 11 additions & 4 deletions lib/request-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
import * as rax from 'retry-axios';

import axiosCookieJarSupport from 'axios-cookiejar-support';
import { wrapper as axiosCookieJarSupport } from 'axios-cookiejar-support';
import extend from 'extend';
import FormData from 'form-data';
import { OutgoingHttpHeaders } from 'http';
import { Agent } from 'https';
import isStream from 'isstream';
import { stringify } from 'querystring';
import { gzipSync } from 'zlib';
import { CookieJar } from 'tough-cookie';
import {
buildRequestFileObject,
isEmptyObject,
Expand Down Expand Up @@ -104,8 +105,14 @@ export class RequestWrapper {
if (axiosOptions.jar) {
axiosCookieJarSupport(this.axiosInstance);

this.axiosInstance.defaults.withCredentials = true;
this.axiosInstance.defaults.jar = axiosOptions.jar;
// axios-cookiejar-support < 2.x accepted a boolean
// some SDKs might be using that, so create a default
// CookieJar if detecting true.
if (axiosOptions.jar === true) {
this.axiosInstance.defaults.jar = new CookieJar();
} else {
this.axiosInstance.defaults.jar = axiosOptions.jar;
}
}

// get retry config properties and conditionally enable retries
Expand Down Expand Up @@ -249,7 +256,7 @@ export class RequestWrapper {
data,
raxConfig: this.raxConfig,
responseType: options.responseType || 'json',
paramsSerializer: (params) => stringify(params),
paramsSerializer: { serialize: (params) => stringify(params) },
};

return this.axiosInstance(requestParams).then(
Expand Down