Skip to content

Commit

Permalink
fix(keep-alive): dont pass undefined property
Browse files Browse the repository at this point in the history
resolves PERS-OPS
  • Loading branch information
sonicoder86 committed Oct 25, 2018
1 parent 068e001 commit 08c9dd7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ class RequestWrapper {
transformResponse: [body => body],
maxContentLength: this.requestOptions.maxContentLength,
validateStatus: () => true,
cancelToken: source.token,
httpAgent: this.requestOptions.httpAgent,
httpsAgent: this.requestOptions.httpsAgent
cancelToken: source.token
};

if (this.requestOptions.httpAgent && this.requestOptions.httpsAgent) {
axiosOptions.httpAgent = this.requestOptions.httpAgent;
axiosOptions.httpsAgent = this.requestOptions.httpsAgent;
}

return axios
.request(axiosOptions)
.then(
Expand Down
21 changes: 21 additions & 0 deletions lib/wrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const axios = require('axios');
const Wrapper = require('./wrapper');
const SuiteRequestError = require('./requestError');
const RequestOption = require('./requestOption');
const http = require('http');
const https = require('https');

describe('Wrapper', function() {
let apiResponse;
Expand Down Expand Up @@ -73,6 +75,25 @@ describe('Wrapper', function() {
expect(response).to.be.eql(expectedApiResponse);
const requestArgument = requestGetStub.args[0][0];
expect(requestArgument).to.containSubset(expectedRequestOptions);
expect(requestArgument).not.to.have.own.property('httpAgent');
expect(requestArgument).not.to.have.own.property('httpsAgent');
});

it('should pass http agents to axios', function *() {
const agents = {
httpAgent: new http.Agent({ keepAlive: true }),
httpsAgent: new https.Agent({ keepAlive: true })
};
wrapper = new Wrapper(
Object.assign(agents, escherRequestOptions),
'http:'
);

yield wrapper.send();

const requestArgument = requestGetStub.args[0][0];
expect(requestArgument.httpAgent).to.eql(agents.httpAgent);
expect(requestArgument.httpsAgent).to.eql(agents.httpsAgent);
});

it('should throw error when response code is 400 or above', function *() {
Expand Down

0 comments on commit 08c9dd7

Please sign in to comment.