Feat: introduce make-fetch-happen (#44)

This commit is contained in:
Sukka
2024-10-10 16:30:36 +08:00
committed by GitHub
parent bb07225f6c
commit c75f7fcc76
12 changed files with 656 additions and 99 deletions

View File

@@ -1,6 +1,7 @@
import { createReadlineInterfaceFromResponse } from './fetch-text-by-line';
import { parse as tldtsParse } from 'tldts';
import { fetchWithRetry, defaultRequestInit } from './fetch-retry';
import { $fetch } from './make-fetch-happen';
import type { NodeFetchResponse } from './make-fetch-happen';
const isDomainLoose = (domain: string): boolean => {
const { isIcann, isPrivate, isIp } = tldtsParse(domain);
@@ -14,7 +15,7 @@ export const extractDomainsFromFelixDnsmasq = (line: string): string | null => {
return null;
};
export const parseFelixDnsmasqFromResp = async (resp: Response): Promise<string[]> => {
export const parseFelixDnsmasqFromResp = async (resp: Response | NodeFetchResponse): Promise<string[]> => {
const results: string[] = [];
for await (const line of createReadlineInterfaceFromResponse(resp)) {
@@ -27,7 +28,7 @@ export const parseFelixDnsmasqFromResp = async (resp: Response): Promise<string[
return results;
};
export const parseFelixDnsmasq = async (url: string | URL): Promise<string[]> => {
const resp = await fetchWithRetry(url, defaultRequestInit);
export const parseFelixDnsmasq = async (url: string): Promise<string[]> => {
const resp = await $fetch(url);
return parseFelixDnsmasqFromResp(resp);
};