New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

net module #7577

Merged
merged 62 commits into from Oct 31, 2016

Conversation

Projects
None yet
6 participants
@aliib

aliib commented Oct 12, 2016

This pull request proposes a new electron module called the net module. It is essentially a JavaScript binding of Chromium native networking library (the net library) and provides an API similar to the Node.js HTTP module.

Currently, Electron apps developers are expected to use the native Node.js, or other helper libraries built on top of it, to issue their HTTP(S) requests. However, it is widely known that Node.js provides a quite minimal support for web proxies.

Using Chromium network stack offers substantial advantages over the HTTP/HTTPS implementation of Node.js, specifically regarding web proxies’ support. Following is a non-exhaustive list of such features:

  • Automatic management of system proxy configuration, support of wpad protocol and proxy pac configuration files.
  • Tunneling of HTTPS requests.
  • Support for authenticating proxies using basic, digest, NTLM, Kerberos or negotiate authentication schemes.
  • Traffic monitoring proxies: Fiddler-like proxies used for access control and monitoring.

While it is possible to provide support for most of the previously listed features on top of Node.js, eventually using additional npm packages, the task is not trivial and requires a substantial development effort and testing. Moreover, we are not aware of any public npm package that solves the authenticating proxies’ issue.

The initial design of Node.js as server-side platform explains while it has always lacked reasonable support for web proxies as the latters are typically deployed in client environments.

Electron, being primarily targeted as a client-side framework, is expected to provide a robust networking API capable of automatically handling all issues introduced by usage of web proxies.

The present module solves all of the aforementioned problems. The API is quite simple and greatly mimics the familiar Node.j HTTP. So no substantial learning effort is required.

The implementation of the net module follows the usual binding patterns of electron. It extends the JavaScript context of the browser process by adding a new module. Applicative code not using the new module wouldn’t be impacted in any aspect.

On the other hand, applications willing to use the new module would automatically benefit from a robust and widely used networking layer targeted for client-side environments.

ali.ibrahim added some commits Sep 15, 2016

ali.ibrahim
ali.ibrahim

@zcbenz zcbenz self-assigned this Oct 24, 2016

@zcbenz

This comment has been minimized.

Show comment
Hide comment
@zcbenz

zcbenz Oct 24, 2016

Contributor

This is something I always wanted to do but never tried, awesome work! 🎆

The PR is very large so the my review will take some time.

Contributor

zcbenz commented Oct 24, 2016

This is something I always wanted to do but never tried, awesome work! 🎆

The PR is very large so the my review will take some time.

Show outdated Hide outdated filenames.gypi
Show outdated Hide outdated docs/api/net.md
Show outdated Hide outdated filenames.gypi
Show outdated Hide outdated lib/browser/api/net.js
Show outdated Hide outdated lib/browser/api/net.js
Show outdated Hide outdated atom/browser/api/atom_api_url_request.cc
Show outdated Hide outdated atom/browser/api/atom_api_url_request.h
Show outdated Hide outdated atom/browser/api/atom_api_url_request.cc
Show outdated Hide outdated atom/browser/api/atom_api_url_request.cc
Show outdated Hide outdated atom/browser/api/atom_api_url_request.h
@aliib

This comment has been minimized.

Show comment
Hide comment
@aliib

aliib Oct 25, 2016

thanks for the review.

aliib commented Oct 25, 2016

thanks for the review.

@davej

This comment has been minimized.

Show comment
Hide comment
@davej

davej Oct 25, 2016

Contributor

Awesome. Am I correct to think this means requests using the net module will appear in the network panel of the Dev Tools?

It may be worthwhile to explicitly document the specific API differences between net and node's http/https modules. I imagine a lot of people will be looking to transition their code to net instead so it would be handy to know what API differences to look out for when migrating.

Contributor

davej commented Oct 25, 2016

Awesome. Am I correct to think this means requests using the net module will appear in the network panel of the Dev Tools?

It may be worthwhile to explicitly document the specific API differences between net and node's http/https modules. I imagine a lot of people will be looking to transition their code to net instead so it would be handy to know what API differences to look out for when migrating.

@aliib

This comment has been minimized.

Show comment
Hide comment
@aliib

aliib Oct 26, 2016

@davej
I don't think we would be able to see net module requests in the network panel of a Dev Tools.
net requests are not associated with any particular page while a Dev Tools page shows network requests for a particular page. If, at some point, Electron provides a Browser-process Dev Tools, then yes it would be feasible to inspect net module requests. However, contrary to Node.js requests, net module requests will automatically appear in usual traffic-inspection tools such as Fiddler.

aliib commented Oct 26, 2016

@davej
I don't think we would be able to see net module requests in the network panel of a Dev Tools.
net requests are not associated with any particular page while a Dev Tools page shows network requests for a particular page. If, at some point, Electron provides a Browser-process Dev Tools, then yes it would be feasible to inspect net module requests. However, contrary to Node.js requests, net module requests will automatically appear in usual traffic-inspection tools such as Fiddler.

@zcbenz

zcbenz approved these changes Oct 31, 2016

@zcbenz

This comment has been minimized.

Show comment
Hide comment
@zcbenz

zcbenz Oct 31, 2016

Contributor

👍

Contributor

zcbenz commented Oct 31, 2016

👍

@zcbenz zcbenz merged commit dfefa00 into electron:master Oct 31, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
@MarshallOfSound

This comment has been minimized.

Show comment
Hide comment
@MarshallOfSound

MarshallOfSound Oct 31, 2016

Member

@zeke Needs to be added to the docs seeds

Member

MarshallOfSound commented Oct 31, 2016

@zeke Needs to be added to the docs seeds

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