Skip to content

Commit

Permalink
Added imeout parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
hgouveia committed Mar 14, 2022
1 parent 7af95f9 commit c2c5714
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ these are the default values
body: null, // Request body, can be any, string, object, etc.
method: 'GET', // Request Method Verb
headers: {}, // Custom HTTP Header ex: Authorization, User-Agent
timeout: -1, // Request timeout in milliseconds (-1 use default), is the equivalent of 'httpRequestOptions: { timeout: value }' (also applied to https)
fileName: string|cb(fileName, filePath, contentType)|{name, ext}, // Custom filename when saved
retry: false, // { maxRetries: number, delay: number in ms } or false to disable (default)
forceResume: false, // If the server does not return the "accept-ranges" header, can be force if it does support it
Expand Down
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class DownloaderHelper extends EventEmitter {
method: 'GET',
headers: {},
fileName: '',
timeout: -1, // -1 use default
override: false, // { skip: false, skipSmaller: false }
forceResume: false,
removeOnStop: true,
Expand Down Expand Up @@ -249,6 +250,11 @@ export class DownloaderHelper extends EventEmitter {
this.__opts = Object.assign({}, this.__opts, options);
this.__headers = this.__opts.headers;

if (this.__opts.timeout > -1) {
this.__opts.httpRequestOptions.timeout = this.__opts.timeout;
this.__opts.httpsRequestOptions.timeout = this.__opts.timeout;
}

// validate the progressThrottle, if invalid, use the default
if (typeof this.__opts.progressThrottle !== 'number' || this.__opts.progressThrottle < 0) {
this.__opts.progressThrottle = this.__defaultOpts.progressThrottle;
Expand Down

0 comments on commit c2c5714

Please sign in to comment.