Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxyRequest does not proxy the Accept header #709

Open
StevenPewsey opened this issue Mar 18, 2024 · 1 comment
Open

proxyRequest does not proxy the Accept header #709

StevenPewsey opened this issue Mar 18, 2024 · 1 comment

Comments

@StevenPewsey
Copy link

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

@brc-dd
Copy link
Contributor

brc-dd commented Mar 18, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants