Automated merging of multiple slashes
URLs get all their extra slashes merged into a single one.
For e.g. this /some/endpoint// gets transformed into this /some/endpoint/, which is not the desired behavior for some particular cases.
By simply removing .replace(/\/+/g, '/') inside the urlJoin function (lib\http-proxy\common.js) you can overcome the problem, but I guess this is not the intended way of working with the node-http-proxy.
One possible fix for this would be to allow the user of the library to intercept the urlJoin call so that he could do some final changes to the URL before it gets proxied.
Hmm this is a good question, right now there is not a good way to handle both cases because there are people that have the opposite assumption when merging URLs together. Whats the example you are trying to make work? I'd love it in test form so we can work towards a solution that works for all cases or is at least configurable in some way.
The URL that's being proxied looks like this:
/api/files//path/to/folder
The parameter of the REST API endpoint is /path/to/folder, which causes the final URL to look like this /api/files//path/to/folder, so there are no accidental double slashes here.
A solid fix in userland is to encode the API parameter, which you probably ought to be doing anyway.
In JavaScript you would do that with:
'/api/files/' + encodeURIComponent('/path/to/folder');
And thus make a request to:
/api/files/%2Fpath%2Fto%2Ffolder
That's a good idea. Nevertheless this implies that the server should know to decode it.
Right. This is a quirk of taking it in the path. Many libraries will automatically decode anything coming in via a query string. Not sure offhand about this module, but if you could switch to that, maybe it would reduce the burden on your implementation.