Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/sdk/server-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"license": "Apache-2.0",
"dependencies": {
"@launchdarkly/js-server-sdk-common": "2.16.0",
"https-proxy-agent": "^5.0.1",
"https-proxy-agent": "^7.0.6",
"launchdarkly-eventsource": "2.2.0"
},
"devDependencies": {
Expand Down
20 changes: 11 additions & 9 deletions packages/sdk/server-node/src/platform/NodeRequests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import * as http from 'http';
import * as https from 'https';
import * as createHttpsProxyAgent from 'https-proxy-agent';
import { HttpsProxyAgentOptions } from 'https-proxy-agent';
import { HttpsProxyAgent, HttpsProxyAgentOptions } from 'https-proxy-agent';
// No types for the event source.
// @ts-ignore
import { EventSource as LDEventSource } from 'launchdarkly-eventsource';
import { format as formatUrl } from 'url';
import { promisify } from 'util';
import * as zlib from 'zlib';

Expand Down Expand Up @@ -52,11 +52,13 @@ function processProxyOptions(
proxyOptions: LDProxyOptions,
additional: https.AgentOptions = {},
): https.Agent | http.Agent {
const protocol = proxyOptions.scheme?.startsWith('https') ? 'https:' : 'http';
const parsedOptions: HttpsProxyAgentOptions & { [index: string]: any } = {
const proxyUrl = formatUrl({
protocol: proxyOptions.scheme?.startsWith('https') ? 'https:' : 'http:',
slashes: true,
hostname: proxyOptions.host,
port: proxyOptions.port,
host: proxyOptions.host,
protocol,
});
const parsedOptions: HttpsProxyAgentOptions<string> = {
...additional,
};
if (proxyOptions.auth) {
Expand All @@ -67,12 +69,12 @@ function processProxyOptions(

// Node does not take kindly to undefined keys.
Object.keys(parsedOptions).forEach((key) => {
if (parsedOptions[key] === undefined) {
delete parsedOptions[key];
if (parsedOptions[key as keyof HttpsProxyAgentOptions<string>] === undefined) {
delete parsedOptions[key as keyof HttpsProxyAgentOptions<string>];
}
});

return createHttpsProxyAgent(parsedOptions);
return new HttpsProxyAgent(proxyUrl, parsedOptions);
}

function createAgent(
Expand Down