electron/spec/fixtures/api/utility-process/net.js
Samuel Attard 74af96da16
build: update some build dependencies (#43882)
* build: update some build dependencies

* build: fix eslint issues after updating

* build: disable ts check on busted js example

* build: update internal types for stricter event handling

* restore url.parse behavior

* fix typing issues

* sigh

* build: update easy deps

* build: skip woa engines check
2024-09-26 00:12:11 -07:00

44 lines
1.4 KiB
JavaScript

const { net } = require('electron');
const serverUrl = process.argv[2].split('=')[1];
let configurableArg = null;
if (process.argv[3]) {
configurableArg = process.argv[3].split('=')[0];
}
const data = [];
let request = null;
if (configurableArg === '--omit-credentials') {
request = net.request({ method: 'GET', url: serverUrl, credentials: 'omit' });
} else if (configurableArg === '--use-fetch-api') {
net.fetch(serverUrl).then((response) => {
process.parentPort.postMessage([response.status, response.headers]);
});
} else {
request = net.request({ method: 'GET', url: serverUrl });
}
if (request) {
if (configurableArg === '--use-net-login-event') {
request.on('login', (authInfo, provideCredentials) => {
process.parentPort.postMessage(authInfo);
provideCredentials('user', 'pass');
});
}
request.on('response', (response) => {
process.parentPort.postMessage([response.statusCode, response.headers]);
response.on('data', (chunk) => data.push(chunk));
response.on('end', (chunk) => {
if (chunk) data.push(chunk);
process.parentPort.postMessage(Buffer.concat(data).toString());
});
});
if (configurableArg === '--request-data') {
process.parentPort.on('message', (e) => {
request.write(e.data);
request.end();
});
process.parentPort.postMessage('get-request-data');
} else {
request.end();
}
}