diff --git a/packages/node-utils/src/edge-to-node/headers.ts b/packages/node-utils/src/edge-to-node/headers.ts index 39484313..4c1c9075 100644 --- a/packages/node-utils/src/edge-to-node/headers.ts +++ b/packages/node-utils/src/edge-to-node/headers.ts @@ -1,22 +1,13 @@ -import type { Headers } from '@edge-runtime/primitives' +import { Headers } from '@edge-runtime/primitives' import type { OutgoingHttpHeaders, ServerResponse } from 'node:http' -import { splitCookiesString } from '@edge-runtime/cookies' -export function toOutgoingHeaders( - headers?: Headers & { raw?: () => Record }, -): OutgoingHttpHeaders { +export function toOutgoingHeaders(headers?: Headers): OutgoingHttpHeaders { const outputHeaders: OutgoingHttpHeaders = {} if (headers) { - for (const [name, value] of typeof headers.raw !== 'undefined' - ? Object.entries(headers.raw()) - : headers.entries()) { - outputHeaders[name] = value - if (name.toLowerCase() === 'set-cookie') { - outputHeaders[name] = - headers.getSetCookie?.() ?? - headers.getAll?.('set-cookie') ?? - splitCookiesString(value) - } + const _headers = new Headers(headers).entries() + for (const [name, value] of _headers) { + outputHeaders[name] = + name === 'set-cookie' ? headers.getSetCookie() : value } } return outputHeaders