Support Happy Eyeballs in proxy-agent
This commit is contained in:
parent
eae9e570fc
commit
56ba8fea4d
13 changed files with 419 additions and 289 deletions
|
@ -2,7 +2,6 @@
|
|||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import URL from 'url';
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import type { RequestInit } from 'node-fetch';
|
||||
import { Response, Headers } from 'node-fetch';
|
||||
import type { connection as WebSocket } from 'websocket';
|
||||
|
@ -14,6 +13,7 @@ import { strictAssert } from '../util/assert';
|
|||
import { BackOff, FIBONACCI_TIMEOUTS } from '../util/BackOff';
|
||||
import * as durations from '../util/durations';
|
||||
import { sleep } from '../util/sleep';
|
||||
import { createProxyAgent } from '../util/createProxyAgent';
|
||||
import { SocketStatus } from '../types/SocketStatus';
|
||||
import * as Errors from '../types/errors';
|
||||
import * as Bytes from '../Bytes';
|
||||
|
@ -68,7 +68,7 @@ export class SocketManager extends EventListener {
|
|||
|
||||
private credentials?: WebAPICredentials;
|
||||
|
||||
private readonly proxyAgent?: ReturnType<typeof ProxyAgent>;
|
||||
private readonly proxyAgent?: ReturnType<typeof createProxyAgent>;
|
||||
|
||||
private status = SocketStatus.CLOSED;
|
||||
|
||||
|
@ -84,7 +84,7 @@ export class SocketManager extends EventListener {
|
|||
super();
|
||||
|
||||
if (options.proxyUrl) {
|
||||
this.proxyAgent = new ProxyAgent(options.proxyUrl);
|
||||
this.proxyAgent = createProxyAgent(options.proxyUrl);
|
||||
}
|
||||
|
||||
this.hasStoriesDisabled = options.hasStoriesDisabled;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
|
||||
import type { Response } from 'node-fetch';
|
||||
import fetch from 'node-fetch';
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
import type { Agent } from 'https';
|
||||
import { escapeRegExp, isNumber, isString, isObject } from 'lodash';
|
||||
import PQueue from 'p-queue';
|
||||
|
@ -29,6 +28,7 @@ import { toWebSafeBase64, fromWebSafeBase64 } from '../util/webSafeBase64';
|
|||
import { getBasicAuth } from '../util/getBasicAuth';
|
||||
import { isPnpEnabled } from '../util/isPnpEnabled';
|
||||
import { createHTTPSAgent } from '../util/createHTTPSAgent';
|
||||
import { createProxyAgent } from '../util/createProxyAgent';
|
||||
import type { SocketStatus } from '../types/SocketStatus';
|
||||
import { VerificationTransport } from '../types/VerificationTransport';
|
||||
import { toLogFormat } from '../types/errors';
|
||||
|
@ -117,7 +117,7 @@ const GET_ATTACHMENT_CHUNK_TIMEOUT = 10 * durations.SECOND;
|
|||
type AgentCacheType = {
|
||||
[name: string]: {
|
||||
timestamp: number;
|
||||
agent: ReturnType<typeof ProxyAgent> | Agent;
|
||||
agent: ReturnType<typeof createProxyAgent> | Agent;
|
||||
};
|
||||
};
|
||||
const agents: AgentCacheType = {};
|
||||
|
@ -256,7 +256,7 @@ async function _promiseAjax(
|
|||
}
|
||||
agents[cacheKey] = {
|
||||
agent: proxyUrl
|
||||
? new ProxyAgent(proxyUrl)
|
||||
? createProxyAgent(proxyUrl)
|
||||
: createHTTPSAgent({
|
||||
keepAlive: !options.disableSessionResumption,
|
||||
maxCachedSessions: options.disableSessionResumption ? 0 : undefined,
|
||||
|
@ -1360,7 +1360,7 @@ export function initialize({
|
|||
|
||||
let fetchForLinkPreviews: linkPreviewFetch.FetchFn;
|
||||
if (proxyUrl) {
|
||||
const agent = new ProxyAgent(proxyUrl);
|
||||
const agent = createProxyAgent(proxyUrl);
|
||||
fetchForLinkPreviews = (href, init) => fetch(href, { ...init, agent });
|
||||
} else {
|
||||
fetchForLinkPreviews = fetch;
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
// Copyright 2021 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type ProxyAgent from 'proxy-agent';
|
||||
import { client as WebSocketClient } from 'websocket';
|
||||
import type { connection as WebSocket } from 'websocket';
|
||||
|
||||
|
@ -10,6 +9,7 @@ import { strictAssert } from '../util/assert';
|
|||
import { explodePromise } from '../util/explodePromise';
|
||||
import { getUserAgent } from '../util/getUserAgent';
|
||||
import * as durations from '../util/durations';
|
||||
import type { createProxyAgent } from '../util/createProxyAgent';
|
||||
import { createHTTPSAgent } from '../util/createHTTPSAgent';
|
||||
import * as log from '../logging/log';
|
||||
import * as Timers from '../Timers';
|
||||
|
@ -28,7 +28,7 @@ export type ConnectOptionsType<Resource extends IResource> = Readonly<{
|
|||
url: string;
|
||||
certificateAuthority?: string;
|
||||
version: string;
|
||||
proxyAgent?: ReturnType<typeof ProxyAgent>;
|
||||
proxyAgent?: ReturnType<typeof createProxyAgent>;
|
||||
timeout?: number;
|
||||
extraHeaders?: Record<string, string>;
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
// Copyright 2022 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import ProxyAgent from 'proxy-agent';
|
||||
|
||||
import type {
|
||||
CDSAuthType,
|
||||
CDSRequestOptionsType,
|
||||
|
@ -11,6 +9,7 @@ import type {
|
|||
import type { LoggerType } from '../../types/Logging';
|
||||
import { isOlderThan } from '../../util/timestamp';
|
||||
import { HOUR } from '../../util/durations';
|
||||
import { createProxyAgent } from '../../util/createProxyAgent';
|
||||
|
||||
// It is 24 hours, but we don't want latency between server and client to be
|
||||
// count.
|
||||
|
@ -31,14 +30,14 @@ export abstract class CDSBase<
|
|||
Options extends CDSBaseOptionsType = CDSBaseOptionsType
|
||||
> {
|
||||
protected readonly logger: LoggerType;
|
||||
protected readonly proxyAgent?: ReturnType<typeof ProxyAgent>;
|
||||
protected readonly proxyAgent?: ReturnType<typeof createProxyAgent>;
|
||||
protected cachedAuth?: CachedAuthType;
|
||||
|
||||
constructor(protected readonly options: Options) {
|
||||
this.logger = options.logger;
|
||||
|
||||
if (options.proxyUrl) {
|
||||
this.proxyAgent = new ProxyAgent(options.proxyUrl);
|
||||
this.proxyAgent = createProxyAgent(options.proxyUrl);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue