Removal of multiple slashes in url
If an url contains multiple slashes like /test**//_test2 it will be automatically converted to /test/**_test2 before proxing.
Is this a bug or feature? If it's a feature, is it possible to disable this? :-)
I changed
https://github.com/nodejitsu/node-http-proxy/blob/master/lib/http-proxy/common.js#L82
to
outgoing.path = (targetPath !== '') ? common.urlJoin(targetPath, outgoingPath) : outgoingPath;
Now it works for me, but I think the problem still exists when prependPath is enabled.
@luke- There are some old issues where we had a lot of people complaining about double slashes which is why the urlJoin method was created. Could you give me the example your using which currently fails? I'd like to cover all the cases as cleanly as possible. Showing me in the form of a test case would be great :smile:
@jcrugzz Imo the the proxy itself shouldn't modify the url, also when it's strange :-) My problem was related to a web app which uses path style parameters e.g.http://example.com/controller/action/param1/value1/param2/value2 if value1 is empty in a special case the produced url was http://example.com/controller/action/param1//param2/value2 which couldn't proxied.
Another problem is that url.parse('http://something.com/foo/bar?next_url=http://something.com/baz') results in:
{ protocol: 'http:',
slashes: true,
auth: null,
host: 'something.com',
port: null,
hostname: 'something.com',
hash: null,
search: '?next_url=http://something.com/baz',
query: 'next_url=http://something.com/baz',
pathname: '/foo/bar',
path: '/foo/bar?next_url=http://something.com/baz',
href: 'http://something.com/foo/bar?next_url=http://something.com/baz' }
Notice that the path contains the querystring. The logic that does double slash replacement mucks up the http:// in the querystring and turns it into http:/.
RFC-3986 section on Query states that / is an allowed character in the query string so it does not need to be percent escaped. The replace code in question should not touch these slashes.
@parente if you can wire up a failing test for me in the tests ill take a stab at making this work for all cases
I'll take a crack at a test. I do need to amend my comment above, however: the code does special case the correction of :// in the query string after replacing // to /. But other cases like comment=//testing will still break.
Is this issue still waiting on a failing test case ?
I faced the same issue: target server that I'm trying to proxy to accepts double slashes
What I'm not following is why after applying Boolean filter you still want to apply regex
//
// Join all strings, but remove empty strings so we don't get extra slashes from
// joining e.g. ['', 'am']
//
retSegs = [
args.filter(Boolean).join('/')
.replace(/\/+/g, '/')
.replace('http:/', 'http://')
.replace('https:/', 'https://')
];
Comment explicitly states, that below piece of code wants to remove empty string, and Boolean filter does this
Possible fix and test case - https://github.com/http-party/node-http-proxy/pull/1487
I just encountered this issue proxy-ing this request:
curl 'localhost:5173/api/cas/sha256-BMB+QrCK1JZa220ajSr2U6gfUsugun//Dbn+uMj/h7w='