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

Automated merging of multiple slashes

Open cosminnicula opened this issue 10 years ago • 5 comments

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.

cosminnicula avatar Feb 13 '16 16:02 cosminnicula

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.

jcrugzz avatar Feb 15 '16 16:02 jcrugzz

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.

cosminnicula avatar Feb 18 '16 08:02 cosminnicula

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

sholladay avatar Feb 22 '16 00:02 sholladay

That's a good idea. Nevertheless this implies that the server should know to decode it.

cosminnicula avatar Feb 22 '16 07:02 cosminnicula

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.

sholladay avatar Feb 22 '16 21:02 sholladay