| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This is the HTTP client for Hackolade Studio and its plugins. It takes into account the proxies and the custom certificate authorities that are configured at the level of the operating system, which removes the need for the end user to deal with complex network settings in Hackolade Studio. It also supports configuring custom network settings in the desktop application if needed.
Web browsers provide natively the Fetch API. In Electron, that API was originally only available in the renderer process (which is basically a browser). It is now also available in the main process and in utility processes via net.fetch. Since that function uses the Chrome's network stack, it also benefits from the integration with the OS trust store (for validating self-signed-certificates) and network settings (for detecting proxies).
This library returns the proper implementation of fetch() depending on the runtime context:
This library also provides extensions to modular SDK's that allow setting a custom HTTP client:
This library aims at being a drop-in replacement for node-fetch. node-fetch can be replaced by @hackolade/fetch using NPM overrides.
"overrides": {
"node-fetch": {
".": "npm:@hackolade/fetch@x.y.z"
}
}We need to test that this library behaves as expected in various situations, whatever the OS of the user:
In order to perform those tests, we have prepared multiple components:
| Component | URL | Description |
|---|---|---|
| server | On your host (direct access): http://127.0.0.1:8080 https://127.0.0.1:4443 In Docker network (access through proxy): http://server:8080 https://server:4443 |
This server exposes the following REST endpoint: PUT /initiators/:connectionType/:initiator It allows clients to register themselves using arbitrary routes: /initiators/direct/main, initiators/proxy/renderer, etc. This server also exposes the following REST endpoint: GET /initiators/:connectionType/:initiator It can be used to check if a given client managed to reach the server to register itself. |
| app | NA | This is an Electron application. It contacts the server from both the main process, a renderer process and a utility process. Each process registers itself as a distinct :initiator: main, renderer and utility respectively. The base URL of the endpoint - including the :connectionType - is passed to the application through an environment variable, making it possible to start different instances of the application to cover different cases (e.g. direct connection, connection through a proxy). |
| proxy | http://127.0.0.1:3128 | This is a proxy that does not require authentication. |
| proxy-basic-auth | http://127.0.0.1:3129 | This is a proxy that requires basic authentication. You can use user1 as both username and password. |
| proxy-https-inspection | http://127.0.0.1:3130 | This is a proxy that performs HTTPS inspection using a self-signed certificate. |
| PAC file | http://127.0.0.1:8081/proxy.pac | This is a PAC file that leads to using the proxy that does not require authentication. |
| tests | NA | This is a set of tests that query the REST API of the server to verify that all clients could successfully register themselves, whatever the context of the connection. |
Follow the instructions below prior to executing the tests:
You can run the command below to execute the automated tests.
npm run docker:test⚠️ Those tests validate the behavior of the library in Docker/Linux. Validating the behavior of the library in MacOS and Windows involve manual steps that are documented below.
See next sections for more details...
| Linux | MacOS | Windows | Notes | |
|---|---|---|---|---|
| Direct connection | ✅ | ✅ | ✅ | |
| OS SETTINGS | Test cases for proxy settings and certificate authorities from the OS | |||
| Self-signed certificate | ✅ | ✅ | ✅ | |
| Proxy | ✅ | ✅ | ✅ | |
| Proxy with basic auth | ✅ | ⚠️ | ⚠️ | 'login' event not emitted for main process (see issue #44249) |
| PAC file | ⚠️ | ✅ | ✅ | Not natively supported by the Linux OS |
| Proxy with HTTPS inspection | ✅ | ✅ | ✅ | |
| APP SETTINGS | Test cases for proxy settings and certificate authorities configured in the app | |||
| Self-signed certificate | ✅ | ⚠️ | ⚠️ | setCertificateVerifyProc() ignored by utility process (see issue #44264) |
| Proxy | ✅ | ✅ | ✅ | |
| Proxy with basic auth | ✅ | ⚠️ | ⚠️ | 'login' event not emitted for main process (see issue #44249) |
| PAC file | ✅ | ✅ | ✅ |
In this case, the app connects directly to the server. There is no intermediate proxy involved.
✅ Linux: this case is covered by the automated tests.
✅ MacOS, ✅ Windows: follow the instructions below.
The test cases that are described in this section cover the integration with the OS trust store (for validating self-signed-certificates) and network settings (for detecting proxies).
For a certificate to be considered valid, it must be signed by a trusted certificate authority (CA), such as GlobalSign or DigiCert. Obtaining such a certificate used to cost some money (this is not true anymore thanks to Let's Encrypt, a nonprofit certificate authority). That's why some organizations generated their own self-signed certificates, typically for internal use. Those certificates are free. However, they are unsafe and prevent HTTPS connections from being established. To be able to use self-signed certificates, an organization must add itself to the list of trusted certificate authorities in the OS of all its users.
✅ Linux: this case is covered by the automated tests. Note that the custom certificate authority must be added to the NSS Shared DB (see instructions here).
✅ MacOS: follow the instructions below.
✅ Windows: follow the instructions below.
In this case, the app connects to the server through a proxy that has been configured in the OS.
✅ Linux: this case is covered by the automated tests. Note that the proxy is configured through the environment variables HTTP_PROXY and HTTPS_PROXY, which is the standard way of configuring proxies in Linux.
✅ MacOS: follow the instructions below.
✅ Windows: follow the instructions below.
In this case, the app connects to the server through a proxy that has been configured in the OS. That proxy requires a username and a password. Even though the username and the password might have been set at the level of the operating system, the user needs to provide them interactively to the Electron application. It is also the case for other apps such as Slack or Docker Desktop.
The main process must handle the login event and prompt the user for the proxy credentials.
const { app } = require('electron');
app.on('login', (event, webContents, details, authInfo, callback) => {
// Prevent the default behavior since it cancels all authentications.
event.preventDefault();
// Prompt the user for credentials
// ...
callback(username, password);
});The login handler will be called automatically for both the main process and a renderer process. For a utility process, the option respondToAuthRequestsFromMainProcess must be set to true when creating it.
const { utilityProcess } = require('electron');
utilityProcess.fork(..., { respondToAuthRequestsFromMainProcess: true });✅ Linux: this case is covered by the automated tests. Note that the proxy is configured through the environment variables HTTP_PROXY and HTTPS_PROXY, which is the standard way of configuring proxies in Linux.
⚠️ MacOS: follow the instructions below. Note that the server cannot be contacted from the main process because the 'login' event (see code snippet above) is not emitted for that process, which ultimately leads to a HTTP #407 Proxy Authentication Required.
✅ Windows: follow the instructions below.
In this case, the app connects to the server through the proxy that is returned by a PAC file that has been configured in the OS.
⚠️ Linux: PAC files are not natively supported by Linux, aka you cannot set HTTP_PROXY or HTTPS_PROXY to the URL of a PAC file. Linux requires the application itself to provide support for PAC files. That's because PAC files were originally meant to be used by browsers (see here). That's why they are JavaScript files.
✅ MacOS: follow the instructions below.
✅ Windows: follow the instructions below.
HTTPS inspection is the process of checking encrypted web traffic. It relies on a proxy that sets up two separate encrypted connections:
Note that the proxy can use a self-signed certificate. This means that establishing the connection with a server can require a custom certificate authority even though the server uses a valid certificate.
✅ Linux: this case is covered by the automated tests.
✅ MacOS: follow the instructions below.
✅ Windows: follow the instructions below.
The test cases that are described in this section cover the configuration of custom network settings in the application itself.
In this case, the app connects to a server that uses a self-signed certificate. The corresponding certificate authority has not been installed in the trust store of the operating system: it is configured directly in the application. You can find here the code that installs that certificate authority in the application.
✅ Linux: this case is covered by the automated tests.
⚠️ MacOS, ⚠️ Windows: follow the instructions below. Note that the server cannot be contacted from the utility process because it ignores the custom procedure that we set for verifying the certificate (see session.setCertificateVerifyProc()).
In this case, the app connects to the server through a proxy that has been configured in the app itself. You can find here the code that applies the given proxy settings.
✅ Linux: this case is covered by the automated tests.
✅ MacOS, ✅ Windows: follow the instructions below.
In this case, the app connects to the server through a proxy that has been configured in the app itself. That proxy requires a username and a password.
✅ Linux: this case is covered by the automated tests.
⚠️ MacOS, ⚠️ Windows: follow the instructions below. Note that the server cannot be contacted from the main process because the 'login' event is not emitted for that process, which ultimately leads to a HTTP #407 Proxy Authentication Required.
In this case, the app connects to the server through the proxy that is returned by a PAC file that has been configured in the app itself.
✅ Linux: this case is covered by the automated tests.
✅ MacOS, ✅ Windows: follow the instructions below.
TypeScript does not require you to specify the file extensions in imports and exports. However, the TypeScript code of this library is ultimately transpiled to both CommonJS and ESM. ESM requires imports and exports to be fully specified, aka to include the file extensions (see here). The problem is that TypeScript transpilers do not modify imported and exported paths (see here). So the only workaround is to use the .js extension in the TypeScript imports and exports in order to be compliant with the ESM requirement (see here).
This problem is related to line break differences between operating systems. To fix it, just save the Dockerfile using the LF line break (e.g. from the status bar in Visual Studio Code).
When reporting an issue in the Electron repository, you need to provide a standalone test case that reproduces the problem. You can do this easily by using Electron Fiddle. You can connect it to your GitHub account and easily upload a test case as a public gist that you can then link from the GitHub issue that you are creating.
Examples:
| Back | FazBrowse Home | New Git URL |