From 8c5467ce2d922ca6a32bae9decc467211a8427ff Mon Sep 17 00:00:00 2001 From: Kir_Antipov Date: Thu, 4 Jan 2024 10:26:02 +0000 Subject: [PATCH] Added proper support for `MultiMap` to `getHeader` --- src/utils/net/headers.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/utils/net/headers.ts b/src/utils/net/headers.ts index 7b912b0..a0209cd 100644 --- a/src/utils/net/headers.ts +++ b/src/utils/net/headers.ts @@ -38,13 +38,18 @@ export function getHeader(headers: Headers, header: string): string | undefined return undefined; } + if (isMultiMap(headers)) { + const entries = headers.get(header); + return typeof entries === "string" ? entries : entries ? asArrayLike(entries).join(HEADER_SEPARATOR) : undefined; + } + if (isMap(headers)) { return headers.get(header); } - if (isIterable(headers)) { + if (isIterable>(headers)) { const arrayLikeHeaders = asArrayLike(headers); - return arrayLikeHeaders.find(x => asArrayLike(x).at(0) === header); + return arrayLikeHeaders.find(x => asArrayLike(x).at(0) === header)?.[1]; } return headers[header];