-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
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
Forwarded Origin header not updated on proxied WebSocket requests #16557
Comments
I think export default defineConfig({
server: {
proxy: {
'/api': {
target: 'http://localhost:4567',
changeOrigin: true,
ws: true,
},
},
},
} |
Thanks @sapphi-red. I'll re-check that and confirm. |
So it looks like I'll put the PR to draft while I dig into why http-proxy does not change the origin |
Ok. changeOrigin does not do what we might think it does - see chimurai/http-proxy-middleware#141 and http-party/node-http-proxy#1130. There's an argument for http-proxy changing or renaming that setting but since Vite passes it straight through I think we should not attempt to conflate the I'll add a clarifying documentation change to my PR when I get a chance and un-draft. |
Describe the bug
When Proxying to a WebSocket service in local development the socket connection can rejected by the server as the
Host
andOrigin
header values do not match. This Origin-limiting behaviour is recommended in RFC 6455 and is implemented in the Java websockets API and the Gorillas websocket package.The Vite proxy is intended as a convenience for local development rather than use in production. I therefore think Vite proxy should support it out-of-the-box.
I don't have a reproduction I can share but have been able to verify that upstream socket servers that implement RFC-6455 return a 403 and this causes the Vite proxy to error on initial connection.
I'm happy to raise a PR.
Reproduction
n/a
Steps to reproduce
With a vite project that connects to a remote RFC-6455 compliant websocket server without using CORS.
Steps:
npm start
Expected:
ws request responds with a 101 Upgrade and the socket is established
Actual:
ws request receives no response and its status is
Finished
System Info
Used Package Manager
npm
Logs
Click to expand!
Validations
The text was updated successfully, but these errors were encountered: