Skip to content

Commit

Permalink
feat: Add disableStreamPassthrough request options
Browse files Browse the repository at this point in the history
  • Loading branch information
rlyonbox committed Nov 2, 2023
1 parent 5f49464 commit 1ca81b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/api-request-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions tests/lib/api-request-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
Expand Down

0 comments on commit 1ca81b4

Please sign in to comment.