node-http-proxy
node-http-proxy copied to clipboard
Proxying ws URL: double slashes converted to single slash
Hi,
Thanks for the great project. We're using node-http-proxy in production and very happy with it.
Recently, we started to use this to proxy ws requests. In combination with https://github.com/RemoteDebug/remotedebug-ios-webkit-adapter/ where we sometimes need to proxy URLs like this: /ios_SIMULATOR/ws://127.0.0.1:9323/devtools/page/1
Due to the line below, these paths are changed into /ios_SIMULATOR/ws:/127.0.0.1:9323/devtools/page/1
which causes issues for us.
So in short, the ws://127....
is converted to ws:/127....
https://github.com/http-party/node-http-proxy/blob/9bbe486c5efcc356fb4d189ef38eee275bbde345/lib/http-proxy/common.js#L190
Possible fix and test case - https://github.com/http-party/node-http-proxy/pull/1487
Possible fix and test case - #1487
I do not see why this fix would solve the issue. It only solves cases with http
or https
but there could be various cases why a url contains //
the issue from testingbot mentions ws://
we encountered this problem here https://github.com/unjs/nitro/issues/1357.
would be nice to have some fix for that
urls like that:
domain.com/content//wp-json/wp/v2/pages
could not be accepted via proxy now, because converter to
domain.com/content/wp-json/wp/v2/pages
https://github.com/http-party/node-http-proxy/issues/959 here found a workaround
Unfortunately, workaround above didn't help, but found even older issue with that behavior: https://github.com/http-party/node-http-proxy/issues/775
In the end, finished with workaround like that:
"/content": {
target: "https://domain.com/content@",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/content\//, ""),
configure: (proxy, options) => {
proxy.on("proxyReq", (proxyReq) => {
// hack for https://github.com/http-party/node-http-proxy/issues/1420
proxyReq.path = proxyReq.path.replace("@", "/");
});
},
},
in a snippet above, part of the route @ will be replaced to / and we will get correct URL with double / https://domain.com/content//method/get