Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
? joinPath(baseUrlParts.pathname, url.pathname)
: baseUrlParts.pathname
: url.pathname;
const search = url.search
? baseUrlParts.search
? `${baseUrlParts.search}&${url.search.slice(1)}`
: url.search
: baseUrlParts.search;
if (search) {
path += search;
}
if (body && !headers['content-length']) {
headers['content-length'] = String(Buffer.byteLength(body));
}
if (!headers['authorization']) {
headers['authorization'] = `Basic ${btoa(
baseUrlParts.auth || 'root:'
)}`;
}
const options: ClientRequestArgs = { path, method, headers, agent };
if (socketPath) {
options.socketPath = socketPath;
} else {
options.host = baseUrlParts.hostname;
options.port = baseUrlParts.port;
}
let called = false;
try {
const req = (isTls ? httpsRequest : httpRequest)(
options,
(res: IncomingMessage) => {
notifyAboutPhaseEnd(requestInstrumentation, 'waiting');