@petitchevalroux/http-download-stream
Advanced tools
Comparing version 1.2.1 to 1.2.2
{ | ||
"name": "@petitchevalroux/http-download-stream", | ||
"version": "1.2.1", | ||
"version": "1.2.2", | ||
"description": "Node transform stream downloading url in input with retry and rate limit", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -13,3 +13,3 @@ "use strict"; | ||
constructor(options) { | ||
options = Object.assign({ | ||
const instanceOptions = Object.assign({ | ||
"timeout": 5000, | ||
@@ -24,7 +24,7 @@ "followRedirect": true, | ||
}, options || {}); | ||
if (typeof(options.httpClient) === "undefined") { | ||
if (typeof(instanceOptions.httpClient) === "undefined") { | ||
this.httpClient = request.defaults({ | ||
"timeout": options.timeout, | ||
"followRedirect": options.followRedirect, | ||
"maxRedirects": options.maxRedirects, | ||
"timeout": instanceOptions.timeout, | ||
"followRedirect": instanceOptions.followRedirect, | ||
"maxRedirects": instanceOptions.maxRedirects, | ||
"gzip": true, | ||
@@ -36,7 +36,8 @@ "headers": { | ||
} else { | ||
this.httpClient = options.httpClient; | ||
this.httpClient = instanceOptions.httpClient; | ||
} | ||
this.limiter = new RateLimiter(options.rateCount, options.rateWindow); | ||
this.retries = options.retries; | ||
this.retryMinTimeout = options.retryMinTimeout; | ||
this.limiter = new RateLimiter(instanceOptions.rateCount, | ||
instanceOptions.rateWindow); | ||
this.retries = instanceOptions.retries; | ||
this.retryMinTimeout = instanceOptions.retryMinTimeout; | ||
} | ||
@@ -83,9 +84,13 @@ | ||
self.attempt(url, function(err, response) { | ||
if (!err && response.output.statusCode > | ||
499) { | ||
if (attempt <= self.retries) { | ||
err = 499; | ||
} | ||
} | ||
if (operation.retry(err)) { | ||
if (operation.retry(err || ( | ||
response.output.statusCode > | ||
499 ? | ||
new Error( | ||
"Wrong http status " + | ||
JSON.stringify({ | ||
status: response | ||
.output | ||
.statusCode, | ||
url: url | ||
})) : false))) { | ||
return; | ||
@@ -92,0 +97,0 @@ } |
74895
461