node-http-proxy icon indicating copy to clipboard operation
node-http-proxy copied to clipboard

Proxying ws URL: double slashes converted to single slash

Open testingbot opened this issue 5 years ago • 7 comments

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

testingbot avatar Feb 16 '20 12:02 testingbot

Possible fix and test case - https://github.com/http-party/node-http-proxy/pull/1487

imagekitio avatar Nov 23 '20 07:11 imagekitio

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.

alexan avatar Jun 29 '23 15:06 alexan

would be nice to have some fix for that

nosovk avatar Feb 17 '24 00:02 nosovk

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

nosovk avatar Feb 17 '24 00:02 nosovk

https://github.com/http-party/node-http-proxy/issues/959 here found a workaround

nosovk avatar Feb 17 '24 00:02 nosovk

Unfortunately, workaround above didn't help, but found even older issue with that behavior: https://github.com/http-party/node-http-proxy/issues/775

nosovk avatar Feb 17 '24 00:02 nosovk

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

nosovk avatar Feb 22 '24 22:02 nosovk