Skip to content

Commit

Permalink
remove getAll and raw usage
Browse files Browse the repository at this point in the history
  • Loading branch information
balazsorban44 committed Sep 7, 2023
1 parent fde1d53 commit cc10154
Showing 1 changed file with 6 additions and 15 deletions.
21 changes: 6 additions & 15 deletions packages/node-utils/src/edge-to-node/headers.ts
Original file line number Diff line number Diff line change
@@ -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<string, string> },
): 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
Expand Down

0 comments on commit cc10154

Please sign in to comment.