UNPKG

@push.rocks/smartproxy

Version:

A powerful proxy package with unified route-based configuration for high traffic management. Features include SSL/TLS support, flexible routing patterns, WebSocket handling, advanced security options, and automatic ACME certificate management.

98 lines (97 loc) 3.25 kB
import * as plugins from '../../plugins.js'; import '../../core/models/socket-augmentation.js'; import { type IHttpProxyOptions } from './models/types.js'; import { SharedRouteManager as RouteManager } from '../../core/routing/route-manager.js'; import { ConnectionPool } from './connection-pool.js'; import { SecurityManager } from './security-manager.js'; /** * Interface for tracking metrics */ export interface IMetricsTracker { incrementRequestsServed(): void; incrementFailedRequests(): void; } export type MetricsTracker = IMetricsTracker; /** * Handles HTTP request processing and proxying */ export declare class RequestHandler { private options; private connectionPool; private routeManager?; private functionCache?; private router?; private defaultHeaders; private logger; private metricsTracker; private h2Sessions; private contextCreator; securityManager: SecurityManager; private rateLimitCleanupInterval; constructor(options: IHttpProxyOptions, connectionPool: ConnectionPool, routeManager?: RouteManager, functionCache?: any, // FunctionCache - using any to avoid circular dependency router?: any); /** * Set the route manager instance */ setRouteManager(routeManager: RouteManager): void; /** * Set the metrics tracker instance */ setMetricsTracker(tracker: IMetricsTracker): void; /** * Set default headers to be included in all responses */ setDefaultHeaders(headers: { [key: string]: string; }): void; /** * Get all default headers */ getDefaultHeaders(): { [key: string]: string; }; /** * Select the appropriate target from the targets array based on sub-matching criteria */ private selectTarget; /** * Apply CORS headers to response if configured * Implements Phase 5.5: Context-aware CORS handling * * @param res The server response to apply headers to * @param req The incoming request * @param route Optional route config with CORS settings */ private applyCorsHeaders; /** * Apply default headers to response */ private applyDefaultHeaders; /** * Apply URL rewriting based on route configuration * Implements Phase 5.2: URL rewriting using route context * * @param req The request with the URL to rewrite * @param route The route configuration containing rewrite rules * @param routeContext Context for template variable resolution * @returns True if URL was rewritten, false otherwise */ private applyUrlRewriting; /** * Apply header modifications from route configuration * Implements Phase 5.1: Route-based header manipulation */ private applyRouteHeaderModifications; /** * Handle an HTTP request */ handleRequest(req: plugins.http.IncomingMessage, res: plugins.http.ServerResponse): Promise<void>; /** * Handle HTTP/2 stream requests with function-based target support */ handleHttp2(stream: plugins.http2.ServerHttp2Stream, headers: plugins.http2.IncomingHttpHeaders): Promise<void>; /** * Cleanup resources and stop intervals */ destroy(): void; }