UNPKG

curl-cffi

Version:

A powerful HTTP client for Node.js based on libcurl with browser fingerprinting capabilities.

228 lines (213 loc) 8.64 kB
import { CurlMulti, Curl, CurlOpt } from '@tocha688/libcurl'; export { Curl, CurlError, CurlHttpVersion, CurlInfo, CurlIpResolve, CurlMOpt, CurlOpt, CurlSslVersion, CurlWsFlag } from '@tocha688/libcurl'; import * as tough_cookie from 'tough-cookie'; import { CookieJar } from 'tough-cookie'; type CURL_IMPERSONATE_EDGE = "edge99" | "edge101"; type CURL_IMPERSONATE_CHROME = "chrome99" | "chrome100" | "chrome101" | "chrome104" | "chrome107" | "chrome110" | "chrome116" | "chrome119" | "chrome120" | "chrome123" | "chrome124" | "chrome131" | "chrome133a" | "chrome136" | "chrome99_android" | "chrome131_android"; type CURL_IMPERSONATE_SAFARI = "safari153" | "safari155" | "safari170" | "safari172_ios" | "safari180" | "safari180_ios" | "safari184" | "safari184_ios" | "safari260" | "safari260_ios"; type CURL_IMPERSONATE_FIREFOX = "firefox133" | "firefox135" | "tor145"; type CURL_IMPERSONATE_DEFAULT = "chrome" | "firefox1" | "safar"; type CURL_IMPERSONATE = CURL_IMPERSONATE_EDGE | CURL_IMPERSONATE_CHROME | CURL_IMPERSONATE_SAFARI | CURL_IMPERSONATE_FIREFOX | CURL_IMPERSONATE_DEFAULT; type CurlData = { curl: Curl; options: RequestOptions; resolve: (res?: CurlResponse) => void; reject: (err?: Error) => void; }; declare class CurlMultiTimer extends CurlMulti { private forceTimeoutTimer; private timers; curls: Map<string, CurlData>; private sockfds; constructor(); private startForceTimeout; /** * 设置回调函数 */ private setupCallbacks; private processData; private isCecker; private checkProcess; request(ops: RequestOptions, curl: Curl): Promise<any>; close(): void; } declare class CurlMultiImpl extends CurlMultiTimer { } type RequestAuth = { username: string; password: string; }; type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS' | string; type RequestCert = { key: string; cert: string; }; type IpType = 'ipv4' | 'ipv6' | 'auto'; type HttpVersion = "v1" | "v2" | "v3" | "v3only" | "v2tls" | "v2_prior_knowledge"; type RequestOptions = { method?: RequestMethod; url?: string; params?: Record<string, any>; data?: Record<string, any> | string | null; jar?: CookieJar; headers?: Record<string, string>; auth?: RequestAuth; timeout?: number; allowRedirects?: boolean; maxRedirects?: number; proxy?: string; referer?: string; acceptEncoding?: string; impersonate?: CURL_IMPERSONATE; ja3?: string; akamai?: string; defaultHeaders?: boolean; defaultEncoding?: string; httpVersion?: HttpVersion | number; interface?: string; cert?: string | RequestCert; verify?: boolean; maxRecvSpeed?: number; curlOptions?: Record<CurlOpt, string | number | boolean>; ipType?: IpType; impl?: CurlMultiImpl; retryCount?: number; keepAlive?: boolean; sync?: boolean; dev?: boolean; cors?: boolean; }; type FetchOptions = RequestOptions & { body?: string | Record<string, any> | null; sync?: boolean; }; type CurlOptions = RequestOptions & { MaxConnects?: number; MaxConcurrentStreams?: number; }; type CurlRequestInfo = RequestOptions & { response: CurlResponse; }; type RequestEvent = (options: RequestOptions) => Promise<RequestOptions>; type ResponseEvent = (options: CurlResponse) => Promise<CurlResponse>; interface CurlRequestimpl { request(options: RequestOptions): Promise<CurlResponse>; get(url: string, params?: Record<string, any>, options?: RequestOptions): Promise<CurlResponse>; post(url: string, data?: Record<string, any>, options?: RequestOptions): Promise<CurlResponse>; put(url: string, data?: Record<string, any>, options?: RequestOptions): Promise<CurlResponse>; delete(url: string, data?: Record<string, any>, options?: RequestOptions): Promise<CurlResponse>; patch(url: string, data?: Record<string, any>, options?: RequestOptions): Promise<CurlResponse>; head(url: string, options?: RequestOptions): Promise<CurlResponse>; options(url: string, options?: RequestOptions): Promise<CurlResponse>; } declare class HttpHeaders { head?: string; headers: Map<string, string[]>; private readonly lowercaseHeaders; constructor(headers?: Record<string, string> | HttpHeaders | string); get status(): number; private normalizeKey; set(key: string, value: string | string[]): Map<string, string[]> | undefined; get(key: string): string[] | null; first(key: string): string | undefined; delete(key: string): void; has(key: string): boolean; all(): { [k: string]: string[]; }; toObject(): Record<string, string>; toArray(): string[]; toString(): string; clone(): HttpHeaders; } type CurlResponseOptions = { headers: HttpHeaders; dataRaw?: Buffer; request: CurlRequestInfo; url: string; stacks?: Array<CurlRequestInfo>; options: RequestOptions; index?: number; curl: Curl; }; declare class CurlResponse { url: string; status: number; dataRaw?: Buffer; headers: HttpHeaders; request: CurlRequestInfo; options: RequestOptions; stacks: Array<CurlRequestInfo>; index: number; redirects: number; curl: Curl; constructor(opts: CurlResponseOptions); get text(): string | undefined; get data(): any; get jar(): CookieJar | undefined; } declare const defaultRequestOption: Partial<RequestOptions>; declare function fetch(url: string, options?: FetchOptions): Promise<CurlResponse>; type RequestData = Record<string, any> | string | URLSearchParams; declare class CurlRequestImplBase { baseOptions: RequestOptions; constructor(baseOptions?: RequestOptions); protected init(): void; protected request(options: RequestOptions): Promise<CurlResponse>; protected beforeRequest(options: RequestOptions): Promise<CurlResponse>; get(url: string, options?: RequestOptions): Promise<CurlResponse>; post(url: string, data?: RequestData, options?: RequestOptions): Promise<CurlResponse>; put(url: string, data?: RequestData, options?: RequestOptions): Promise<CurlResponse>; delete(url: string, data?: RequestData, options?: RequestOptions): Promise<CurlResponse>; patch(url: string, data?: RequestData, options?: RequestOptions): Promise<CurlResponse>; head(url: string, options?: RequestOptions): Promise<CurlResponse>; options(url: string, options?: RequestOptions): Promise<CurlResponse>; get jar(): tough_cookie.CookieJar | undefined; } declare class CurlClient extends CurlRequestImplBase { private multi?; constructor(ops?: CurlOptions); private reqs; private resps; private emits; onRequest(event: RequestEvent): void; onResponse(event: ResponseEvent): void; private initOptions; protected send(options: RequestOptions, curl: Curl): Promise<CurlResponse>; protected getCurl(): Curl; protected beforeResponse(options: RequestOptions, curl: Curl, res: CurlResponse): Promise<CurlResponse>; request(options: RequestOptions): Promise<CurlResponse>; close(): void; setImpl(impl?: CurlMultiImpl): void; getImpl(): CurlMultiImpl | undefined; } declare class CurlSession extends CurlClient { constructor(ops?: RequestOptions); private curlCheckTimer?; private startCheckCurlClose; private curls; getCurl(): Curl; close(): void; beforeResponse(options: RequestOptions, curl: Curl, res: CurlResponse): Promise<CurlResponse>; } declare const storageCurls: Set<any>; declare const req: CurlClient; declare enum LogLevel { none = 0, error = 1, info = 2, warn = 3, debug = 4 } declare class Logger { static level: LogLevel; private constructor(); private static time; static info(...args: any[]): void; static debug(...args: any[]): void; static warn(...args: any[]): void; static error(...args: any[]): void; } declare const libVersion: () => string; declare const libPath: () => string | null; export { type CURL_IMPERSONATE, type CURL_IMPERSONATE_CHROME, type CURL_IMPERSONATE_DEFAULT, type CURL_IMPERSONATE_EDGE, type CURL_IMPERSONATE_FIREFOX, type CURL_IMPERSONATE_SAFARI, CurlClient, CurlMultiImpl, type CurlOptions, type CurlRequestInfo, type CurlRequestimpl, CurlResponse, type CurlResponseOptions, CurlSession, type FetchOptions, HttpHeaders, type HttpVersion, type IpType, LogLevel, Logger, type RequestAuth, type RequestCert, type RequestEvent, type RequestMethod, type RequestOptions, type ResponseEvent, defaultRequestOption, fetch, libPath, libVersion, req, storageCurls };