proxyRequest does not proxy the Accept header
StevenPewsey opened this issue · comments
Environment
Node 18.16.1
Reproduction
N/A
Describe the bug
Following #646, proxyRequest ignores any Accept
headers.
This is breaking my application (following a nuxt upgrade from 3.9 -> 3.11) as we proxy api requests via the server to a backend API, which requires us to send through an Accept
header.
As a fix for the timebeing I can explicitly pass through the Accept
header as follows
return proxyRequest(event, targetPath, {
headers: {
Accept: event.headers.get('Accept') || ''
}
})
but this feels a bit unnecessary to me, I would have expected h3 to send through this header by default.
Additional context
No response
Logs
No response
I too believe this was a bit of breaking change and doesn't work as expected. I'm using nuxt's routeRules
to specify proxies and I don't think there's any way to manually forward headers from there. For API responses, I can probably hard code it:
routeRules: {
'/api/**': {
proxy: {
to: '...',
headers: { accept: 'application/json' }
}
},
But I also have stuff like:
'/images/**': {
proxy: {
to: '...'
}
},
I want the backend to be able to determine what the browser supports. Currently it always responds with the fallback format instead of modern ones like avif even if the browser support them because that info is removed while proxying.
For the time being, creating a middleware for proxying and calling proxyRequest like OP wrote seems to work.