#mergeHeaders can't merge instances of Headers

3 messages · Page 1 of 1 (latest)

shrewd wyvern
#

I painfully had to discover, that the mergeHeaders utility won't merge multiple instances of Headers, since Object.entries() of a headers object returns an empty string (See source). I found this issue while debugging a proxy route using the proxyRequest utility of h3. One can pass headers to be set for the request, but because of this behaviour, they will simply vanish.

Working example

const headers: Record<string, string> = {}
if (session.token)
    headers["Authorization"] = `Bearer ${session.token}`
else
    console.warn(`[PROXY] No token set`)
if (session.domain)
    headers["X-Domain"] = session.domain
else
    console.warn(`[PROXY] No domain set`)

return proxyRequest(event, target, { headers })

Headers vanishing example, but no type errors(!!)

const headers = new Headers()
if (session.token)
    headers.set("Authorization", `Bearer ${session.token}`)
else
    console.warn(`[PROXY] No token set`)
if (session.domain)
    headers.set("X-Domain", session.domain)
else
    console.warn(`[PROXY] No domain set`)

return proxyRequest(event, target, { headers })

Now my real question: Is this the expected behaviour?

GitHub

⚡️ Minimal H(TTP) framework built for high performance and portability - unjs/h3

mild wraith
#

@shrewd wyvern worth raisin an issue imo

shrewd wyvern
#

Alright, will do that