From 5fb1afd7b7a938289c17580d9cf5d8e072b9cc9d Mon Sep 17 00:00:00 2001 From: blacksonic Date: Fri, 15 Dec 2017 11:36:19 +0100 Subject: [PATCH] feat(option): make max content length configurable --- lib/requestOption.js | 3 +++ lib/wrapper.js | 2 +- lib/wrapper.spec.js | 9 ++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/lib/requestOption.js b/lib/requestOption.js index 14604ad..1b63652 100644 --- a/lib/requestOption.js +++ b/lib/requestOption.js @@ -1,5 +1,7 @@ 'use strict'; +const MEGA_BYTE = 1000 * 1000; + class SuiteRequestOption { static createForInternalApi(environment, rejectUnauthorized) { @@ -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 = {}; diff --git a/lib/wrapper.js b/lib/wrapper.js index 7bda187..9abaa31 100644 --- a/lib/wrapper.js +++ b/lib/wrapper.js @@ -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 }; diff --git a/lib/wrapper.spec.js b/lib/wrapper.spec.js index 181c3b5..08c14f9 100644 --- a/lib/wrapper.spec.js +++ b/lib/wrapper.spec.js @@ -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; @@ -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',