Skip to content

Commit

Permalink
fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
ronag committed Nov 23, 2024
1 parent 244f20d commit 59bcb75
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion lib/util/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,32 @@ function makeCacheKey (opts) {
throw new Error('opts.origin is undefined')
}

/** @type {Record<string, string[] | string>} */
let headers
if (opts.headers == null) {
headers = {}
} else if (typeof opts.headers[Symbol.iterator] === 'function') {
headers = {}
for (const [key, val] of opts.headers) {
if (typeof key !== 'string' || typeof val !== 'string') {
throw new Error('opts.headers is not a valid header map')
}
headers[key] = val
}
} else if (typeof opts.headers === 'object') {
headers = opts.headers
} else {
throw new Error('opts.headers is not an object')
}

/**
* @type {import('../../types/cache-interceptor.d.ts').default.CacheKey}
*/
const cacheKey = {
origin: opts.origin.toString(),
method: opts.method,
path: opts.path,
headers: opts.headers
headers
}

return cacheKey
Expand Down
2 changes: 1 addition & 1 deletion types/dispatcher.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ declare namespace Dispatcher {
/** Default: `null` */
body?: string | Buffer | Uint8Array | Readable | null | FormData;
/** Default: `null` */
headers?: IncomingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null;
headers?: Record<string, string | string[]> | IncomingHttpHeaders | string[] | Iterable<[string, string | string[] | undefined]> | null;
/** Query string params to be embedded in the request URL. Default: `null` */
query?: Record<string, any>;
/** 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`. */
Expand Down

0 comments on commit 59bcb75

Please sign in to comment.