mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-23 11:41:51 +03:00
27 lines
867 B
TypeScript
27 lines
867 B
TypeScript
import http from 'node:https';
|
|
|
|
import { HttpExecutor } from 'builder-util-runtime';
|
|
import type { ClientRequest } from 'electron';
|
|
|
|
/**
|
|
* For testing and same as:
|
|
* https://github.com/electron-userland/electron-builder/blob/master/packages/electron-updater/src/electronHttpExecutor.ts
|
|
*/
|
|
export class MockedHttpExecutor extends HttpExecutor<ClientRequest> {
|
|
createRequest(
|
|
options: any,
|
|
callback: (response: any) => void
|
|
): ClientRequest {
|
|
if (options.headers && options.headers.Host) {
|
|
// set host value from headers.Host
|
|
options.host = options.headers.Host;
|
|
// remove header property 'Host', if not removed causes net::ERR_INVALID_ARGUMENT exception
|
|
delete options.headers.Host;
|
|
}
|
|
|
|
const request = http.request(options);
|
|
request.on('response', callback);
|
|
return request as unknown as ClientRequest;
|
|
}
|
|
}
|