import http from 'node:http'; import { AsyncLocalStorage } from 'node:async_hooks'; import { TestStepType } from '../models/test-step'; interface ProfilerRef { shouldSkip(url: string): boolean; trackOnFail: boolean; fallbackSteps: TestStepType[]; } export interface RequestInfo { method: string; url: string; } /** * Handles the 3 `http.request()` call signatures: * - (url: string, options?, callback?) * - (url: URL, options?, callback?) * - (options: RequestOptions, callback?) * * Returns `{ method, url }`. Default method is 'GET'. */ export declare function extractRequestInfo(args: [ string | URL | http.RequestOptions, (http.RequestOptions | ((res: http.IncomingMessage) => void))?, ((res: http.IncomingMessage) => void)? ]): RequestInfo; /** * Converts `http.IncomingHttpHeaders` (which has `string | string[] | undefined` values) * to `Record`. Multi-value headers joined with `', '`. Undefined values skipped. */ export declare function headersToRecord(headers: http.IncomingHttpHeaders): Record; /** * Builds a REQUEST-type step from raw timing data. * * `startTime` / `endTime` are expected as `Date.now()` values (ms since epoch). * They are normalized to Unix seconds (with fractional ms) for `step.execution.start_time` / * `end_time` per Qase API spec; `duration` stays in ms. */ export declare function buildRequestStep(params: { method: string; url: string; statusCode: number; responseBody: string | null; responseHeaders: Record | null; startTime: number; endTime: number; }): TestStepType; /** * HttpInterceptor monkey-patches Node.js http/https module functions to capture * outgoing requests as REQUEST-type steps in the AsyncLocalStorage store. * * Pattern: * 1. `install()` — saves originals, replaces with wrappers * 2. `uninstall()` — restores originals */ export declare class HttpInterceptor { private readonly store; private readonly profiler; private origHttpRequest; private origHttpGet; private origHttpsRequest; private origHttpsGet; constructor(store: AsyncLocalStorage, profiler: ProfilerRef); install(): void; uninstall(): void; /** * Creates a wrapper around a http.request-like function. * The wrapper: * 1. Calls the original function to get the ClientRequest * 2. Checks if there's an active ALS context — if not, returns unchanged * 3. Checks shouldSkip — if true, returns unchanged * 4. Intercepts the 'response' event via req.emit override * 5. Builds a TestStepType on response end and pushes to accumulator */ private wrapRequestFn; } export {};