@dividenconquer/cloudflare-proxy-fetch
Version:
A robust HTTP/HTTPS proxy client implementation for Cloudflare Workers with automatic retries and proxy rotation
48 lines • 1.72 kB
TypeScript
import { ProxyFetchOptions } from "./types";
export * from "./types";
export * from "./utils";
/**
* Performs an HTTP(S) request through a proxy server using Cloudflare Workers' Sockets API.
*
* This function implements a full HTTP client that works with HTTP/HTTPS proxies,
* supporting features like:
* - Proxy authentication
* - Automatic retry with proxy rotation
* - Chunked transfer encoding
* - Gzip compression
* - Detailed connection logging
* - Automatic redirect following
*
* @example
* ```typescript
* // Simple usage with a single proxy
* const response = await proxyFetch('https://api.example.com/data', {
* proxy: 'http://username:password@proxy.example.com:8080',
* method: 'POST',
* headers: {
* 'Content-Type': 'application/json'
* },
* body: JSON.stringify({ key: 'value' })
* });
*
* const data = await response.json();
*
* // Advanced usage with proxy rotation and redirects
* const response = await proxyFetch('https://api.example.com/data', {
* proxy: async (attempt) => {
* const proxies = ['proxy1', 'proxy2', 'proxy3'];
* return proxies[attempt % proxies.length];
* },
* maxRetries: 3,
* maxRedirects: 5,
* verbose: true
* });
* ```
*
* @param url - The URL to fetch
* @param options - Combined standard fetch options and proxy-specific options
* @returns A standard Response object with enhanced json() and text() methods
* @throws {Error} If all proxy attempts fail or for other network/protocol errors
*/
export declare function proxyFetch(url: string | URL, { proxy, verbose, maxRetries, retryDelay, maxRedirects, ...options }: ProxyFetchOptions & RequestInit): Promise<Response>;
//# sourceMappingURL=index.d.ts.map