@algolia/requester-node-http
Advanced tools
Comparing version 5.9.1 to 5.10.0-beta.1
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 }; |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20274
213
2
+ Added@algolia/client-common@5.10.0-beta.1(transitive)
- Removed@algolia/client-common@5.9.1(transitive)