From ccb267eae4201748cf6d35391685404508d437ab Mon Sep 17 00:00:00 2001 From: 3846masa <3846masahiro+git@gmail.com> Date: Thu, 2 May 2024 19:56:12 +0900 Subject: [PATCH] chore: fix types for undici v6.7.0 * related: https://github.com/nodejs/undici/pull/2708 --- src/undici/utils/convert_to_headers_object.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/undici/utils/convert_to_headers_object.ts b/src/undici/utils/convert_to_headers_object.ts index 976dd8a8..e26142f8 100644 --- a/src/undici/utils/convert_to_headers_object.ts +++ b/src/undici/utils/convert_to_headers_object.ts @@ -2,8 +2,17 @@ import { errors } from 'undici'; import type { IncomingHttpHeaders } from 'undici/types/header'; +function isIterable(value: unknown): value is Iterable { + return typeof value === 'object' && value != null && Symbol.iterator in value; +} + function convertToHeadersObject( - _headers: IncomingHttpHeaders | (string | Buffer)[] | null | undefined, + _headers: + | IncomingHttpHeaders + | (string | Buffer)[] + | Iterable<[string, string | string[] | undefined]> + | null + | undefined, ): IncomingHttpHeaders { const headers: IncomingHttpHeaders = {}; @@ -27,6 +36,10 @@ function convertToHeadersObject( } } } + } else if (isIterable(_headers)) { + for (const [key, value] of _headers) { + headers[key.toLowerCase()] = value; + } } else if (_headers != null) { for (const [key, value] of Object.entries(_headers)) { headers[key.toLowerCase()] = value;