Skip to content

Commit c3f2b9b

Browse files
committed
Fix breaking bug on url joining resulting in paths like ///path.
Added OS-agnostic url join helper.
1 parent df12aeb commit c3f2b9b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/http-proxy/common.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
7171
? url.parse(req.url).path
7272
: req.url;
7373

74-
outgoing.path = targetPath
75-
? targetPath + '/' + outgoingPath
76-
: outgoingPath;
74+
outgoing.path = common.urlJoin(targetPath, outgoingPath);
7775

7876
return outgoing;
7977
};
@@ -109,4 +107,10 @@ common.getPort = function(req) {
109107
return res ?
110108
res[1] :
111109
req.connection.pair ? '443' : '80' ;
112-
}
110+
};
111+
112+
// OS-agnostic join (doesn't break on URLs like path.join does on Windows)
113+
common.urlJoin = function() {
114+
var args = Array.prototype.slice.call(arguments);
115+
return args.join('/').replace(/\/+/g, '/');
116+
};

0 commit comments

Comments
 (0)