mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2025-12-24 20:26:24 +00:00
Rename files
This commit is contained in:
73
ts/updater/got.node.ts
Normal file
73
ts/updater/got.node.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
// Copyright 2019 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { StrictOptions as GotOptions } from 'got';
|
||||
import config from 'config';
|
||||
import { Agent as HTTPAgent } from 'node:http';
|
||||
|
||||
import { version } from '../util/packageJson.node.js';
|
||||
import { getUserAgent } from '../util/getUserAgent.node.js';
|
||||
import * as durations from '../util/durations/index.std.js';
|
||||
import { createHTTPSAgent } from '../util/createHTTPSAgent.node.js';
|
||||
import { createProxyAgent } from '../util/createProxyAgent.node.js';
|
||||
|
||||
export const GOT_CONNECT_TIMEOUT = durations.MINUTE;
|
||||
export const GOT_LOOKUP_TIMEOUT = durations.MINUTE;
|
||||
export const GOT_SOCKET_TIMEOUT = durations.MINUTE;
|
||||
const GOT_RETRY_LIMIT = 3;
|
||||
|
||||
export function getProxyUrl(): string | undefined {
|
||||
return process.env.HTTPS_PROXY || process.env.https_proxy;
|
||||
}
|
||||
|
||||
export function getCertificateAuthority(): string {
|
||||
return config.get('certificateAuthority');
|
||||
}
|
||||
|
||||
export type { GotOptions };
|
||||
|
||||
export async function getGotOptions(): Promise<GotOptions> {
|
||||
const certificateAuthority = getCertificateAuthority();
|
||||
const proxyUrl = getProxyUrl();
|
||||
const agent = proxyUrl
|
||||
? {
|
||||
http: await createProxyAgent(proxyUrl),
|
||||
https: await createProxyAgent(proxyUrl),
|
||||
}
|
||||
: {
|
||||
http: new HTTPAgent(),
|
||||
https: createHTTPSAgent(),
|
||||
};
|
||||
|
||||
return {
|
||||
agent,
|
||||
https: {
|
||||
certificateAuthority,
|
||||
},
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache',
|
||||
'User-Agent': getUserAgent(version),
|
||||
},
|
||||
timeout: {
|
||||
connect: GOT_CONNECT_TIMEOUT,
|
||||
lookup: GOT_LOOKUP_TIMEOUT,
|
||||
|
||||
// This timeout is reset whenever we get new data on the socket
|
||||
socket: GOT_SOCKET_TIMEOUT,
|
||||
},
|
||||
retry: {
|
||||
limit: GOT_RETRY_LIMIT,
|
||||
errorCodes: [
|
||||
'ETIMEDOUT',
|
||||
'ECONNRESET',
|
||||
'ECONNREFUSED',
|
||||
'EPIPE',
|
||||
'ENOTFOUND',
|
||||
'ENETUNREACH',
|
||||
'EAI_AGAIN',
|
||||
],
|
||||
methods: ['GET', 'HEAD'],
|
||||
statusCodes: [413, 429, 503],
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user