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?