revert: Revert "chore(fetcher): log proxy usage, allow to disable proxy via config"

This reverts commit b67e1b85d6.
This commit is contained in:
WebStreamr 2025-09-14 13:37:08 +00:00
parent dc610bfa64
commit 4ca87f0ff1
No known key found for this signature in database
3 changed files with 22 additions and 18 deletions

View file

@ -8,7 +8,7 @@ import winston from 'winston';
import { BlockedError, HttpError, NotFoundError, QueueIsFullError, TimeoutError, TooManyRequestsError, TooManyTimeoutsError } from '../error';
import { BlockedReason, Context } from '../types';
import { noCache } from './config';
import { createProxyAgent, getProxyForUrl } from './dispatcher';
import { createDispatcher } from './dispatcher';
import { envGet } from './env';
interface HttpCacheItem {
@ -254,9 +254,7 @@ export class Fetcher {
};
protected async fetchWithTimeout(ctx: Context, url: URL, init?: CustomRequestInit, tryCount = 0): Promise<Response> {
const proxyUrl = getProxyForUrl(ctx, url);
this.logger.info(`Fetch ${init?.method ?? 'GET'} ${url} via proxy ${proxyUrl}`, ctx);
this.logger.info(`Fetch ${init?.method ?? 'GET'} ${url}`, ctx);
const isRateLimitedRaw = await this.rateLimitedCache.getRaw<true>(url.host);
/* istanbul ignore if */
@ -284,11 +282,13 @@ export class Fetcher {
finalUrl.username = '';
finalUrl.password = '';
const dispatcher = createDispatcher(ctx, url);
const finalInit = {
...init,
keepalive: true,
signal: AbortSignal.timeout(init?.timeout ?? this.DEFAULT_TIMEOUT),
...(/* istanbul ignore next */ proxyUrl && { dispatcher: createProxyAgent(proxyUrl) }),
...(/* istanbul ignore next */ dispatcher && { dispatcher }),
};
response = await fetch(finalUrl, finalInit);

View file

@ -39,7 +39,7 @@ export class StreamResolver {
const streams: Stream[] = [];
let sourceErrorCount = 0;
let sourceErrorOccurred = false;
const urlResults: UrlResult[] = [];
const sourcePromises = sources.map(async (source) => {
if (!source.contentTypes.includes(type)) {
@ -55,7 +55,7 @@ export class StreamResolver {
urlResults.push(...sourceUrlResults.flat());
} catch (error) {
sourceErrorCount++;
sourceErrorOccurred = true;
if (showErrors(ctx.config)) {
streams.push({
@ -86,7 +86,7 @@ export class StreamResolver {
return a.label.localeCompare(b.label);
});
const errorCount = urlResults.reduce((count, urlResult) => urlResult.error ? count + 1 : count, sourceErrorCount);
const errorCount = urlResults.reduce((count, urlResult) => urlResult.error ? count + 1 : count, 0);
this.logger.info(`Got ${urlResults.length} url results, including ${errorCount} errors`, ctx);
streams.push(
@ -107,7 +107,7 @@ export class StreamResolver {
})),
);
const ttl = sourceErrorCount === 0 ? this.determineTtl(urlResults) : undefined;
const ttl = !sourceErrorOccurred ? this.determineTtl(urlResults) : undefined;
return {
streams,

View file

@ -3,7 +3,15 @@ import { minimatch } from 'minimatch';
import { Dispatcher, ProxyAgent } from 'undici';
import { Context } from '../types';
export const getProxyForUrl = (ctx: Context, url: URL): URL | undefined => {
const createProxyAgent = (proxyUrl: URL): Dispatcher => {
if (proxyUrl.protocol === 'socks5:') {
return socksDispatcher({ type: 5, host: proxyUrl.hostname, port: parseInt(proxyUrl.port) });
}
return new ProxyAgent({ uri: proxyUrl.href });
};
const createBasicDispatcher = (ctx: Context, url: URL): Dispatcher | undefined => {
const proxyConfig = ctx.config['proxyConfig'] || process.env['PROXY_CONFIG'];
if (proxyConfig) {
@ -14,20 +22,16 @@ export const getProxyForUrl = (ctx: Context, url: URL): URL | undefined => {
}
if (hostPattern === '*' || minimatch(url.host, hostPattern)) {
return proxy === 'false' ? undefined : new URL(proxy);
return createProxyAgent(new URL(proxy));
}
}
} else if (process.env['ALL_PROXY']) {
return new URL(process.env['ALL_PROXY']);
return createProxyAgent(new URL(process.env['ALL_PROXY']));
}
return undefined;
};
export const createProxyAgent = (proxyUrl: URL): Dispatcher => {
if (proxyUrl.protocol === 'socks5:') {
return socksDispatcher({ type: 5, host: proxyUrl.hostname, port: parseInt(proxyUrl.port) });
}
return new ProxyAgent({ uri: proxyUrl.href });
export const createDispatcher = (ctx: Context, url: URL): Dispatcher | undefined => {
return createBasicDispatcher(ctx, url);
};