Skip to content

Commit 59bcb75

Browse files
committed
fixup
1 parent 244f20d commit 59bcb75

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/util/cache.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,32 @@ function makeCacheKey (opts) {
1313
throw new Error('opts.origin is undefined')
1414
}
1515

16+
/** @type {Record<string, string[] | string>} */
17+
let headers
18+
if (opts.headers == null) {
19+
headers = {}
20+
} else if (typeof opts.headers[Symbol.iterator] === 'function') {
21+
headers = {}
22+
for (const [key, val] of opts.headers) {
23+
if (typeof key !== 'string' || typeof val !== 'string') {
24+
throw new Error('opts.headers is not a valid header map')
25+
}
26+
headers[key] = val
27+
}
28+
} else if (typeof opts.headers === 'object') {
29+
headers = opts.headers
30+
} else {
31+
throw new Error('opts.headers is not an object')
32+
}
33+
1634
/**
1735
* @type {import('../../types/cache-interceptor.d.ts').default.CacheKey}
1836
*/
1937
const cacheKey = {
2038
origin: opts.origin.toString(),
2139
method: opts.method,
2240
path: opts.path,
23-
headers: opts.headers
41+
headers
2442
}
2543

2644
return cacheKey

types/dispatcher.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ declare namespace Dispatcher {
103103
/** Default: `null` */
104104
body?: string | Buffer | Uint8Array | Readable | null | FormData;
105105
/** Default: `null` */
106-
headers?: IncomingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null;
106+
headers?: Record<string, string | string[]> | IncomingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null;
107107
/** Query string params to be embedded in the request URL. Default: `null` */
108108
query?: Record<string, any>;
109109
/** Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline have completed. Default: `true` if `method` is `HEAD` or `GET`. */

0 commit comments

Comments
 (0)