@socketsecurity/sdk
Advanced tools
Comparing version
@@ -81,3 +81,4 @@ import events from 'node:events'; | ||
]; | ||
const req = getHttpModule(baseUrl).request(`${baseUrl}${urlPath}`, { | ||
const url = new URL(urlPath, baseUrl); | ||
const req = getHttpModule(baseUrl).request(url, { | ||
method: 'POST', | ||
@@ -90,5 +91,15 @@ ...options, | ||
}); | ||
let aborted = false; | ||
req.on('error', _err => { | ||
aborted = true; | ||
}); | ||
req.on('close', () => { | ||
aborted = true; | ||
}); | ||
try { | ||
// Send the request body (headers + files). | ||
for (const part of requestBody) { | ||
if (aborted) { | ||
break; | ||
} | ||
if (typeof part === 'string') { | ||
@@ -102,4 +113,6 @@ req.write(part); | ||
await events.once(part, 'end'); | ||
// Ensure a new line after file content. | ||
req.write('\r\n'); | ||
if (!aborted) { | ||
// Ensure a new line after file content. | ||
req.write('\r\n'); | ||
} | ||
} | ||
@@ -111,5 +124,11 @@ else { | ||
} | ||
catch (e) { | ||
req.destroy(e); | ||
throw e; | ||
} | ||
finally { | ||
// Close request after writing all data. | ||
req.end(); | ||
if (!aborted) { | ||
// Close request after writing all data. | ||
req.end(); | ||
} | ||
} | ||
@@ -116,0 +135,0 @@ return await getResponse(req); |
{ | ||
"name": "@socketsecurity/sdk", | ||
"version": "1.4.31", | ||
"version": "1.4.32", | ||
"license": "MIT", | ||
@@ -92,3 +92,3 @@ "description": "SDK for the Socket API client", | ||
"@eslint/js": "9.26.0", | ||
"@types/node": "22.15.3", | ||
"@types/node": "22.15.14", | ||
"@typescript-eslint/parser": "8.32.0", | ||
@@ -107,4 +107,4 @@ "@vitest/coverage-v8": "3.1.3", | ||
"husky": "9.1.7", | ||
"knip": "5.53.0", | ||
"lint-staged": "15.5.1", | ||
"knip": "5.54.1", | ||
"lint-staged": "15.5.2", | ||
"nock": "14.0.4", | ||
@@ -111,0 +111,0 @@ "npm-run-all2": "8.0.1", |
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
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 too big to display
517456
0.35%12584
0.31%