Skip to content

Commit

Permalink
feat: Stringify ClientRequests as [ClientRequest: <method> <url>]
Browse files Browse the repository at this point in the history
  • Loading branch information
dividedmind committed Mar 19, 2024
1 parent 79c5374 commit f4b8518
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/parameter.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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]",
Expand All @@ -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);
Expand Down

0 comments on commit f4b8518

Please sign in to comment.