Skip to content

Add useNetModule to newHttpRequest#49

Open
okejminja wants to merge 4 commits into
launchdarkly:mainfrom
okejminja:feat-use-net-module
Open

Add useNetModule to newHttpRequest#49
okejminja wants to merge 4 commits into
launchdarkly:mainfrom
okejminja:feat-use-net-module

Conversation

@okejminja
Copy link
Copy Markdown

@okejminja okejminja commented Jun 25, 2025

Requirements

  • I have added test coverage for new or changed functionality
  • I have followed the repository's pull request submission guidelines
  • I have validated my changes against all supported platform versions

Related issues

/

Describe the solution you've provided

  • Added a new argument called useNetModule that will use Electron's net module instead of request
  • Added an empty array to types property in tsconfig.json to prevent @types libraries from node_modules from being checked when running npm run check-typescript

Describe alternatives you've considered

/

Additional context

/


Note

Medium Risk
Changes the SDK's underlying HTTP transport in the main process when useNetModule is enabled, which could affect request behavior across environments (headers, TLS/proxy handling, abort semantics). Scoped behind an opt-in flag with added tests, so overall impact is moderate.

Overview
Adds an opt-in useNetModule option that routes main-process HTTP calls through Electron’s net module instead of Node’s http/https in newHttpRequest (with automatic fallback when net isn’t available).

Plumbs the option through electronPlatform and test harness wiring, updates TypeScript typings to expose useNetModule, and adds a focused Jest test suite to validate initialization, request headers (User-Agent), and track() behavior when the new transport is enabled.

Updates tsconfig.json to set an empty types list so npm run check-typescript doesn’t implicitly include @types/* packages from node_modules.

Reviewed by Cursor Bugbot for commit de42f02. Bugbot is set up for automated code reviews on this repo. Configure here.

@okejminja okejminja requested a review from a team as a code owner June 25, 2025 14:09
@classicdocs
Copy link
Copy Markdown

Nice one!

@okejminja
Copy link
Copy Markdown
Author

@kinyoklion @keelerm84 Hey, can you take a look at this PR?

@kinyoklion
Copy link
Copy Markdown
Member

@abarker-launchdarkly Alan is doing some overlapping work currently. So I am going to defer to him.

@gafner
Copy link
Copy Markdown

gafner commented Nov 21, 2025

@kinyoklion @abarker-launchdarkly any updates on this one?

@okejminja okejminja requested a review from a team as a code owner February 24, 2026 21:19
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit de42f02. Configure here.

Comment thread src/httpRequest.js
request.setHeader(key, value);
}

request.on('response', onResponse);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TLS parameters silently ignored when using net module

Medium Severity

When useNetModule is true, the tlsParams argument is accepted but never applied — the electronNet.request() call doesn't incorporate any TLS configuration. A user who sets both useNetModule: true and tlsParams (e.g. a custom ca for self-signed certificates, as shown in LDClient-tls-test.js) will have their TLS configuration silently dropped, potentially causing connection failures or unintended security behavior with no indication of what went wrong.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit de42f02. Configure here.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we introduce this toggle, then we also need to add to the docs that using native net will delegate tls concerns to chromium (I think). This may not work for everyone.

I would also like to have a warning logged if there is a custom tlsParam defined and we are trying to use net.

Copy link
Copy Markdown

@joker23 joker23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution @okejminja and apologies for the very late response.

I can help with moving this along. Overall, I think this PR looks good, but I am concerned about net dropping custom tls configs... I think that if we clearly document this limitation and have sufficient warnings when we run into a possible breaking scenario, then I am good to approve.

Looking forward, we are working on a new major version for this SDK and I am not sure if we would pull this feature over as is. My thoughts are to provide a way for users to override the SDK platform requestor with their https requestor of choice. Would that kind of design satisfy your use case?

Comment thread src/httpRequest.js
request.setHeader(key, value);
}

request.on('response', onResponse);
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we introduce this toggle, then we also need to add to the docs that using native net will delegate tls concerns to chromium (I think). This may not work for everyone.

I would also like to have a warning logged if there is a custom tlsParam defined and we are trying to use net.

Comment thread typings.d.ts
* Initialization options for the LaunchDarkly Electron SDK.
*/
export interface LDOptions extends LDOptionsBase {
useNetModule?: boolean;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above, I think we need to document the caveats as well as what exactly this option does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants