h3 icon indicating copy to clipboard operation
h3 copied to clipboard

`proxyRequest` does not use new req headers set `event.headers.set()`

Open lammerfalcon opened this issue 1 year ago • 3 comments

Environment

Nitro v2.9.6     
Node v20.12.2

Basic nuxt 3 project

Reproduction

https://stackblitz.com/edit/github-c51gfm?file=app.vue,server%2Fapi%2Fauth%2Flogin.post.ts,server%2Fapi%2F%5B...%5D.ts

Describe the bug

import {joinURL} from "ufo";

export default defineEventHandler((event) => {
    const authCookie = getCookie(event, 'authorization')
    const {proxyUrl} = useRuntimeConfig()
    const path = event.path.replace(/^\/api\//, '')
    const target = joinURL(proxyUrl, path)
    event.headers.set('authorization', `Bearer ${authCookie}`) // does not work
    Object.assign(event.node.req.headers, { Authorization: 'Bearer ' + authCookie}) // works
    console.log(event.headers)
    return proxyRequest(event, target, {
        headers:{
            authorization: `Bearer ${authCookie}` // works
        }
    })
})

event.headers.set() does not apply to proxyRequest, but other variants works well

Additional context

No response

Logs

No response

lammerfalcon avatar May 27 '24 12:05 lammerfalcon

Any info?(

lammerfalcon avatar May 30 '24 22:05 lammerfalcon

Hi, sorry for the late reply. Two-way sync is not possible today, unfortunately between event.node and event.node.req.headers

I would suggest to use ...event.node.req.headers in proxy request.

I will move this to more relevant place (h3)

pi0 avatar May 31 '24 10:05 pi0

Hi. With upcoming v2, two way sync will be possible (https://github.com/unjs/h3/pull/829)

pi0 avatar Jul 18 '24 19:07 pi0