MCPcopy Index your code
hub / github.com/promptfoo/promptfoo / getHeadersForCacheKey

Function getHeadersForCacheKey

src/cache.ts:409–431  ·  view source on GitHub ↗
(url: RequestInfo, options: RequestInit)

Source from the content-addressed store, hash-verified

407}
408
409function getHeadersForCacheKey(url: RequestInfo, options: RequestInit) {
410 const headers = new Headers(getFetchWithProxyHeaders(url, options));
411
412 // Mirror monkeyPatchFetch so the cache key reflects the Authorization header that
413 // will actually be sent: fold in the cloud bearer token for cloud-bound requests,
414 // without overriding a caller-supplied Authorization.
415 const cloudAuth = getCloudBearerToken(url);
416 if (cloudAuth && !headers.has('Authorization')) {
417 headers.set('Authorization', cloudAuth);
418 }
419
420 const cloudTaskTeamId = getCloudTaskTeamId(url);
421 if (cloudTaskTeamId && !headers.has(PROMPTFOO_TEAM_ID_HEADER)) {
422 headers.set(PROMPTFOO_TEAM_ID_HEADER, cloudTaskTeamId);
423 }
424
425 return Array.from(headers.entries())
426 .sort(([nameA, valueA], [nameB, valueB]) => {
427 const nameComparison = nameA.localeCompare(nameB);
428 return nameComparison === 0 ? valueA.localeCompare(valueB) : nameComparison;
429 })
430 .map(([name, value]) => [name, getStringForFetchCacheKey(value, name)]);
431}
432
433function hashFetchCacheKey(identity: unknown) {
434 return sha256(JSON.stringify(identity));

Callers 1

getFetchCacheKeyFunction · 0.85

Calls 6

getFetchWithProxyHeadersFunction · 0.90
getCloudBearerTokenFunction · 0.90
getCloudTaskTeamIdFunction · 0.90
hasMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…