Skip to content

Commit

Permalink
feat(option): make max content length configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
sonicoder86 committed Dec 15, 2017
1 parent 58a9e67 commit 5fb1afd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
3 changes: 3 additions & 0 deletions lib/requestOption.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

const MEGA_BYTE = 1000 * 1000;

class SuiteRequestOption {

static createForInternalApi(environment, rejectUnauthorized) {
Expand Down Expand Up @@ -33,6 +35,7 @@ class SuiteRequestOption {
this.prefix = '';
this.timeout = 'timeout' in options ? options.timeout : 15000;
this.allowEmptyResponse = false;
this.maxContentLength = options.maxContentLength || 10 * MEGA_BYTE;

if (!options) {
options = {};
Expand Down
2 changes: 1 addition & 1 deletion lib/wrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class RequestWrapper {
data: reqOptions.body,
timeout: reqOptions.timeout,
transformResponse: [body => body],
maxContentLength: 10000000, // 10 MB
maxContentLength: this.requestOptions.maxContentLength,
validateStatus: () => true
};

Expand Down
9 changes: 4 additions & 5 deletions lib/wrapper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const axios = require('axios');
const Wrapper = require('./wrapper');
const SuiteRequestError = require('./requestError');
const RequestOption = require('./requestOption');

describe('Wrapper', function() {
let apiResponse;
Expand All @@ -25,17 +26,15 @@ describe('Wrapper', function() {
statusMessage: 'OK'
};

escherRequestOptions = {
escherRequestOptions = new RequestOption('very.host.io', {
port: 443,
host: 'very.host.io',
headers: [
['content-type', 'very-format'],
['x-custom', 'alma']
],
method: 'GET',
path: '/purchases/1/content',
timeout: 15000
};
path: '/purchases/1/content'
});

expectedRequestOptions = {
method: 'get',
Expand Down

0 comments on commit 5fb1afd

Please sign in to comment.