diff --git a/src/api-request-manager.ts b/src/api-request-manager.ts index 3ded6868..0a26ac85 100644 --- a/src/api-request-manager.ts +++ b/src/api-request-manager.ts @@ -83,7 +83,7 @@ class APIRequestManager { // available before we can pipe it to the pass-through stream. // If the stream is undefined, then the request failed and we should // propagate the error. - if (stream) { + if (stream && options.disableStreamPassthrough !== true) { var passThrough = new PassThrough(); stream.pipe(passThrough); return passThrough; diff --git a/tests/lib/api-request-manager-test.js b/tests/lib/api-request-manager-test.js index 323dcaeb..ea945b70 100644 --- a/tests/lib/api-request-manager-test.js +++ b/tests/lib/api-request-manager-test.js @@ -228,6 +228,21 @@ describe('APIRequestManager', function() { .withExactArgs() .returns(expectedResponse); response = requestManager.makeStreamingRequest({}); + assert.instanceOf(response, Stream.PassThrough); + assert.equal(typeof response, typeof expectedResponse); + }); + + it('should return the Stream directly when `disableStreamPassthrough` is true', function() { + var requestManager = new APIRequestManager(config, eventBusFake), + expectedResponse = new Stream(), + response; + + sandbox.stub(apiRequestFake, 'execute'); + sandbox.mock(apiRequestFake).expects('getResponseStream') + .withExactArgs() + .returns(expectedResponse); + response = requestManager.makeStreamingRequest({ disableStreamPassthrough: true }); + assert.notInstanceOf(response, Stream.PassThrough); assert.equal(typeof response, typeof expectedResponse); }); });