Skip to content

Commit

Permalink
chore: fix types for undici v6.7.0
Browse files Browse the repository at this point in the history
  • Loading branch information
3846masa committed May 2, 2024
1 parent d2c0a62 commit ccb267e
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/undici/utils/convert_to_headers_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,17 @@
import { errors } from 'undici';
import type { IncomingHttpHeaders } from 'undici/types/header';

function isIterable(value: unknown): value is Iterable<unknown> {
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 = {};

Expand All @@ -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;
Expand Down

0 comments on commit ccb267e

Please sign in to comment.