MCPcopy
hub / github.com/coder/mux / extractRequestContext

Function extractRequestContext

src/node/orpc/formatOrpcError.ts:67–93  ·  view source on GitHub ↗
(interceptorOptions: unknown)

Source from the content-addressed store, hash-verified

65}
66
67function extractRequestContext(interceptorOptions: unknown): RequestContext {
68 if (!isRecord(interceptorOptions)) {
69 return {};
70 }
71
72 const prefix =
73 typeof interceptorOptions.prefix === "string" ? interceptorOptions.prefix : undefined;
74 const request = isRecord(interceptorOptions.request) ? interceptorOptions.request : undefined;
75
76 const method = request && typeof request.method === "string" ? request.method : undefined;
77
78 const urlRaw = request ? request.url : undefined;
79 const url =
80 urlRaw instanceof URL ? urlRaw.toString() : typeof urlRaw === "string" ? urlRaw : undefined;
81
82 const path = urlRaw instanceof URL ? `${urlRaw.pathname}${urlRaw.search}` : undefined;
83
84 const headers = request ? redactHeaders(request.headers) : undefined;
85
86 return {
87 method,
88 url,
89 path,
90 prefix,
91 headers,
92 };
93}
94
95interface JsonSafeOptions {
96 depth: number;

Callers 1

formatOrpcErrorFunction · 0.85

Calls 2

isRecordFunction · 0.70
redactHeadersFunction · 0.70

Tested by

no test coverage detected