Proxying WebSocket requests is broken
Created by: minus7
Describe the bug
Setting the proxy field in package.json proxies normal HTTP requests and WebSocket requests.
For normal requests, the Origin header is patched to equal the target host (added in #1212).
For websocket requests, the onProxyReq hook is not executed and thus the original Origin is sent to the target server. The target server will likely reject the request because Host and Origin mismatch (Gorilla websockts in my case). To also patch Origin for websocket requests, the onProxyReqWs hook has to be specified additionally.
Steps to reproduce
- Add a breakpoint or
console.login theonProxyReqcallback mentioned above. -
yarn startany created project with a configured proxy - Open a websocket connection
- See nothing getting logged because only
onProxyReqWsis called for websocket connections.
Expected behavior
Origin and Host are equal for proxied websocket requests (e.g. http://localhost:8080).
Actual behavior
Origin is the original header sent by the browser (e.g. http://localhost:3000) while Host is changed (e.g. http://localhost:8080).
--
Note: I'd have sent a patch, but I refuse to sign the CLA.