This commit is contained in:
Benjamin Toby 2025-01-21 08:24:29 +01:00
parent 4aa69791c1
commit 9f773de1a1
3 changed files with 26 additions and 15 deletions

View File

@ -31,12 +31,18 @@ function httpRequest(params) {
delete params.scheme;
delete params.query;
delete params.urlEncodedFormBody;
let finalHeaders = {
"Content-Type": isUrlEncodedFormBody
? "application/x-www-form-urlencoded"
: "application/json",
};
if (reqPayloadString) {
finalHeaders["Content-Length"] =
Buffer.from(reqPayloadString).length;
}
finalHeaders = Object.assign(Object.assign({}, finalHeaders), params.headers);
/** @type {import("node:https").RequestOptions} */
const requestOptions = Object.assign(Object.assign({}, params), { headers: Object.assign({ "Content-Type": isUrlEncodedFormBody
? "application/x-www-form-urlencoded"
: "application/json", "Content-Length": reqPayloadString
? Buffer.from(reqPayloadString).length
: undefined }, params.headers), port: paramScheme == "https" ? 443 : params.port, path: finalPath });
const requestOptions = Object.assign(Object.assign({}, params), { headers: finalHeaders, port: paramScheme == "https" ? 443 : params.port, path: finalPath });
const httpsRequest = finalScheme.request(requestOptions,
/**
* Callback Function

View File

@ -37,18 +37,23 @@ export default function httpRequest<
delete params.query;
delete params.urlEncodedFormBody;
let finalHeaders: http.OutgoingHttpHeaders = {
"Content-Type": isUrlEncodedFormBody
? "application/x-www-form-urlencoded"
: "application/json",
};
if (reqPayloadString) {
finalHeaders["Content-Length"] =
Buffer.from(reqPayloadString).length;
}
finalHeaders = { ...finalHeaders, ...params.headers };
/** @type {import("node:https").RequestOptions} */
const requestOptions: import("node:https").RequestOptions = {
...params,
headers: {
"Content-Type": isUrlEncodedFormBody
? "application/x-www-form-urlencoded"
: "application/json",
"Content-Length": reqPayloadString
? Buffer.from(reqPayloadString).length
: undefined,
...params.headers,
},
headers: finalHeaders,
port: paramScheme == "https" ? 443 : params.port,
path: finalPath,
};

View File

@ -1,6 +1,6 @@
{
"name": "@moduletrace/datasquirel",
"version": "3.8.2",
"version": "3.8.3",
"description": "Cloud-based SQL data management tool",
"main": "dist/index.js",
"bin": {