From f4b8518dbdacdd68e0bb9a0bf14b6797450e7cf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Rzepecki?= Date: Wed, 14 Feb 2024 16:54:53 -0500 Subject: [PATCH] feat: Stringify ClientRequests as `[ClientRequest: ]` --- src/parameter.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/parameter.ts b/src/parameter.ts index f3aed17c..62f29bc1 100644 --- a/src/parameter.ts +++ b/src/parameter.ts @@ -1,4 +1,4 @@ -import { IncomingMessage, ServerResponse } from "node:http"; +import { ClientRequest, IncomingMessage, ServerResponse } from "node:http"; import { format, inspect, isDeepStrictEqual } from "node:util"; import type AppMap from "./AppMap"; @@ -37,6 +37,7 @@ function doInspect(value: unknown): string { export function stringify(value: unknown): string { if (value instanceof IncomingMessage) return format("[IncomingMessage: %s %s]", value.method, value.url); + if (value instanceof ClientRequest) return formatClientRequest(value); if (value instanceof ServerResponse) return format( "[ServerResponse: %s]", @@ -49,6 +50,16 @@ export function stringify(value: unknown): string { return result; } +function formatClientRequest(value: ClientRequest): string { + const result = ["[ClientRequest: "]; + if (value.method) result.push(value.method, " "); + if (value.protocol) result.push(value.protocol, "//"); + if (value.host) result.push(value.host); + if (value.path) result.push(value.path); + result.push("]"); + return result.join(""); +} + export function optParameter(value: unknown): AppMap.Parameter | undefined { if (value === undefined) return undefined; return parameter(value);