Checks
Describe the bug (be clear and concise)
It seems that the proxy (websocket) only works on the protocol of the first request.
If a proxy endpoint (the initial request) is first visited with the ws protocol, the proxy will only work on ws.
If you first visit on wss, the proxy will only work on wss.
So if the initial request was on the ws protocol, the proxy won't resolve a response on wss and keeps in the "connecting" state as it keeps waiting for a response from the proxy. This can also be performed the other way around. First wss then ws
Step-by-step reproduction instructions
1. `npm install`
2. `npm run dev`
3. Visit `ws://localhost:3000/`, it will successfully proxy to the websocket server
4. Visit `wss://localhost/`, it will fail to resolve a response
If you re-run the dev command and first visit wss://localhost/, then ws://localhost:3000/ will fail
Repro: https://github.com/Netail/repro-http-proxy-websocket
Expected behavior (be clear and concise)
Proxy should work on both protocols or at least resolve a response
How is http-proxy-middleware used in your project?
repro-http-proxy-websocket@1.0.0 <root>\repro-http-proxy-websocket
└── http-proxy-middleware@3.0.5
What http-proxy-middleware configuration are you using?
https://github.com/Netail/repro-http-proxy-websocket/blob/main/proxy.ts
What OS/version and node/version are you seeing the problem?
System:
OS: Windows 10 10.0.19045
CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz
Memory: 20.45 GB / 31.93 GB
Binaries:
Node: 22.20.0
npm: 11.5.2
pnpm: 10.15.1
bun: 1.2.20
Additional context (optional)
No response
Checks
http-proxy-middleware.Describe the bug (be clear and concise)
It seems that the proxy (websocket) only works on the protocol of the first request.
If a proxy endpoint (the initial request) is first visited with the
wsprotocol, the proxy will only work onws.If you first visit on
wss, the proxy will only work onwss.So if the initial request was on the
wsprotocol, the proxy won't resolve a response onwssand keeps in the "connecting" state as it keeps waiting for a response from the proxy. This can also be performed the other way around. FirstwssthenwsStep-by-step reproduction instructions
If you re-run the dev command and first visit
wss://localhost/, thenws://localhost:3000/will failRepro: https://github.com/Netail/repro-http-proxy-websocket
Expected behavior (be clear and concise)
Proxy should work on both protocols or at least resolve a response
How is http-proxy-middleware used in your project?
What http-proxy-middleware configuration are you using?
https://github.com/Netail/repro-http-proxy-websocket/blob/main/proxy.ts
What OS/version and node/version are you seeing the problem?
System: OS: Windows 10 10.0.19045 CPU: (8) x64 Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz Memory: 20.45 GB / 31.93 GB Binaries: Node: 22.20.0 npm: 11.5.2 pnpm: 10.15.1 bun: 1.2.20Additional context (optional)
No response