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

@algolia/requester-node-http

Package Overview
Dependencies
Maintainers
3
Versions
236
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algolia/requester-node-http - npm Package Compare versions

Comparing version 5.9.1 to 5.10.0-beta.1

89

dist/requester.http.d.ts
import http from 'http';
import https from 'https';
import { URL } from 'url';
import { Requester } from '@algolia/client-common';
// src/createHttpRequester.ts
var agentOptions = { keepAlive: true };
var defaultHttpAgent = new http.Agent(agentOptions);
var defaultHttpsAgent = new https.Agent(agentOptions);
function createHttpRequester({
agent: userGlobalAgent,
httpAgent: userHttpAgent,
httpsAgent: userHttpsAgent,
requesterOptions = {}
} = {}) {
const httpAgent = userHttpAgent || userGlobalAgent || defaultHttpAgent;
const httpsAgent = userHttpsAgent || userGlobalAgent || defaultHttpsAgent;
function send(request) {
return new Promise((resolve) => {
let responseTimeout;
let connectTimeout;
const url = new URL(request.url);
const path = url.search === null ? url.pathname : `${url.pathname}${url.search}`;
const options = {
agent: url.protocol === "https:" ? httpsAgent : httpAgent,
hostname: url.hostname,
path,
method: request.method,
...requesterOptions,
headers: {
...request.headers,
...requesterOptions.headers
}
};
if (url.port && !requesterOptions.port) {
options.port = url.port;
}
const req = (url.protocol === "https:" ? https : http).request(options, (response) => {
let contentBuffers = [];
response.on("data", (chunk) => {
contentBuffers = contentBuffers.concat(chunk);
});
response.on("end", () => {
clearTimeout(connectTimeout);
clearTimeout(responseTimeout);
resolve({
status: response.statusCode || 0,
content: Buffer.concat(contentBuffers).toString(),
isTimedOut: false
});
});
});
const createTimeout = (timeout, content) => {
return setTimeout(() => {
req.destroy();
resolve({
status: 0,
content,
isTimedOut: true
});
}, timeout);
};
connectTimeout = createTimeout(request.connectTimeout, "Connection timeout");
req.on("error", (error) => {
clearTimeout(connectTimeout);
clearTimeout(responseTimeout);
resolve({ status: 0, content: error.message, isTimedOut: false });
});
req.once("response", () => {
clearTimeout(connectTimeout);
responseTimeout = createTimeout(request.responseTimeout, "Socket timeout");
});
if (request.data !== void 0) {
req.write(request.data);
}
req.end();
});
}
return { send };
}
type CreateHttpRequesterOptions = Partial<{
agent: http.Agent | https.Agent;
httpAgent: http.Agent;
httpsAgent: https.Agent;
/**
* RequestOptions to be merged with the end request, it will override default options if provided.
*/
requesterOptions: https.RequestOptions;
}>;
declare function createHttpRequester({ agent: userGlobalAgent, httpAgent: userHttpAgent, httpsAgent: userHttpsAgent, requesterOptions, }?: CreateHttpRequesterOptions): Requester;
export { createHttpRequester };
export { type CreateHttpRequesterOptions, createHttpRequester };

8

package.json
{
"name": "@algolia/requester-node-http",
"version": "5.9.1",
"version": "5.10.0-beta.1",
"description": "Promise-based request library for node using the native http module.",

@@ -37,7 +37,7 @@ "repository": {

"dependencies": {
"@algolia/client-common": "5.9.1"
"@algolia/client-common": "5.10.0-beta.1"
},
"devDependencies": {
"@arethetypeswrong/cli": "0.16.4",
"@types/node": "22.7.5",
"@types/node": "22.7.7",
"nock": "13.5.5",

@@ -47,3 +47,3 @@ "publint": "0.2.11",

"typescript": "5.6.3",
"vitest": "2.1.2"
"vitest": "2.1.3"
},

@@ -50,0 +50,0 @@ "engines": {

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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