MCPcopy Create free account
hub / github.com/nodejs/node / formatRequestKey

Function formatRequestKey

deps/undici/src/lib/mock/snapshot-recorder.js:124–139  ·  view source on GitHub ↗

* Formats a request for consistent snapshot storage * Caches normalized headers to avoid repeated processing * * @param {SnapshotRequestOptions} opts - Request options * @param {import('./snapshot-utils').HeaderFilters} headerFilters - Cached header sets for performance * @param {SnapshotRecord

(opts, headerFilters, matchOptions = {})

Source from the content-addressed store, hash-verified

122 * @returns {SnapshotFormattedRequest} - Formatted request object
123 */
124function formatRequestKey (opts, headerFilters, matchOptions = {}) {
125 const url = new URL(opts.path, opts.origin)
126
127 // Cache normalized headers if not already done
128 const normalized = opts._normalizedHeaders || normalizeHeaders(opts.headers)
129 if (!opts._normalizedHeaders) {
130 opts._normalizedHeaders = normalized
131 }
132
133 return {
134 method: opts.method || 'GET',
135 url: normalizeUrlForMatching(url, matchOptions.matchQuery, matchOptions.normalizeQuery),
136 headers: filterHeadersForMatching(normalized, headerFilters, matchOptions),
137 body: normalizeBodyForMatching(opts.body, matchOptions.matchBody, matchOptions.normalizeBody)
138 }
139}
140
141/**
142 * Filters headers based on matching configuration

Callers 4

recordMethod · 0.85
findSnapshotMethod · 0.85
deleteSnapshotMethod · 0.85
getSnapshotInfoMethod · 0.85

Calls 4

normalizeUrlForMatchingFunction · 0.85
filterHeadersForMatchingFunction · 0.85
normalizeBodyForMatchingFunction · 0.85
normalizeHeadersFunction · 0.70

Tested by

no test coverage detected