Skip to content

Commit

Permalink
Add default configuration and documents
Browse files Browse the repository at this point in the history
  • Loading branch information
congminh1254 committed Nov 3, 2023
1 parent 1ca81b4 commit 67f6dfa
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
11 changes: 11 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ sdk.configure({
});
```

## Disable stream PassThrough for streaming responses

By default the SDK uses `PassThrough` stream to handle streaming responses. It helps to support delayed reading of the response body, but in some cases it can cause memory leaks or not fully works. To disable `PassThrough` stream use the `disableStreamPassThrough` method:

```javascript
sdk = BoxSDKNode.getPreconfiguredInstance(APP_SETTINGS);
sdk.configure({
disableStreamPassThrough: true
});
```

## Configure Base URL

The Base Url is the URL that is used by the SDK to access Box. The default base URL are already defined
Expand Down
6 changes: 5 additions & 1 deletion src/api-request-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ 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 && options.disableStreamPassthrough !== true) {
if (
stream &&
requestConfig.disableStreamPassThrough !== true &&
!options.disableStreamPassThrough
) {
var passThrough = new PassThrough();
stream.pipe(passThrough);
return passThrough;
Expand Down
1 change: 1 addition & 0 deletions src/util/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var defaults = {
iterators: false,
enterpriseID: undefined,
analyticsClient: null,
disableStreamPassThrough: false,
proxy: {
url: null,
username: null,
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/api-request-manager-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ describe('APIRequestManager', function() {
assert.equal(typeof response, typeof expectedResponse);
});

it('should return the Stream directly when `disableStreamPassthrough` is true', function() {
it('should return the Stream directly when `disableStreamPassThrough` is true', function() {
var requestManager = new APIRequestManager(config, eventBusFake),
expectedResponse = new Stream(),
response;
Expand All @@ -241,7 +241,7 @@ describe('APIRequestManager', function() {
sandbox.mock(apiRequestFake).expects('getResponseStream')
.withExactArgs()
.returns(expectedResponse);
response = requestManager.makeStreamingRequest({ disableStreamPassthrough: true });
response = requestManager.makeStreamingRequest({ disableStreamPassThrough: true });
assert.notInstanceOf(response, Stream.PassThrough);
assert.equal(typeof response, typeof expectedResponse);
});
Expand Down

0 comments on commit 67f6dfa

Please sign in to comment.