Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@capriza/http-utils

Package Overview
Dependencies
Maintainers
4
Versions
60
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@capriza/http-utils - npm Package Compare versions

Comparing version 0.2.8 to 0.2.9

37

lib/httpUtils.js
var axios = require('axios');
var BaseUtils = require("./baseUtils");
var Queue = require("./rateLimitQueue");
const CancelToken = axios.CancelToken;
const URL = require('url');

@@ -17,3 +18,3 @@ const responseTypes = ["data", "status", "statusText", "headers", "config", "request"];

this.retryOnNetworkErrors = options.retryOnNetworkErrors || false;
this.requestTimeout = parseInt(options.requestTimeout) || 30 * 1000;
this.requestQueue = new Queue(options.limit, options.interval, options.maxConcurrent);

@@ -23,3 +24,3 @@ this.baseURL = options.baseUrl;

baseURL: options.baseUrl,
timeout: options.requestTimeout || 30000,
timeout: this.requestTimeout,
auth : options.username && options.password && { username : options.username, password : options.password },

@@ -71,4 +72,32 @@ headers: options.headers || {

var doRequest = async () => {
let options = Object.assign(opts, { url, method });
return this.http.request(options);
let source = CancelToken.source();
let options = Object.assign(opts, { url, method, cancelToken: source.token });
return new Promise(async (resolve, reject) => {
let endedRequest = false;
let _end = (func, res) => {
if(endedRequest) return;
endedRequest = true;
func(res);
};
const timeoutThreshold = this.requestTimeout + 3 * 1000;
let timeout = setTimeout(() => {
this.logger.info("request time exceeded");
try {
source.cancel('request was canceled due to time out');
} catch (ex) {
this.logger.error("source.cancel was failed. ex=" + ex);
}
_end(reject, "request was canceled due to timeout. timeout=" + timeoutThreshold);
}, timeoutThreshold);
try {
let res = await this.http.request(options);
_end(resolve, res);
} catch (ex) {
_end(reject, ex);
} finally {
clearTimeout(timeout);
}
});
};

@@ -75,0 +104,0 @@

2

package.json
{
"name": "@capriza/http-utils",
"version": "0.2.8",
"version": "0.2.9",
"description": "HTTP Request utils that handles, request-response, errors, concurrency, priority and authentication",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,1 +0,1 @@

VERSION=0.2.8
VERSION=0.2.9
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc