Skip to content

Commit eb95660

Browse files
committed
Merge pull request #733 from richardkazuomiller/double-slash-fix
do not modify the query string
2 parents fa797fc + 4a2b870 commit eb95660

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

lib/http-proxy/common.js

+19-4
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
7777
if (options.changeOrigin) {
7878
outgoing.headers.host = outgoing.host;
7979
}
80-
80+
8181
return outgoing;
8282
};
8383

@@ -134,9 +134,24 @@ common.getPort = function(req) {
134134

135135
common.urlJoin = function() {
136136
var args = Array.prototype.slice.call(arguments);
137+
138+
// We do not want to mess with the query string. All we want to touch is the path.
139+
var lastIndex = args.length-1;
140+
var last = args[lastIndex]
141+
var lastSegs = last.split('?')
142+
args[lastIndex] = lastSegs[0]
143+
137144
// Join all strings, but remove empty strings so we don't get extra slashes from
138145
// joining e.g. ['', 'am']
139-
return args.filter(function filter(a) {
140-
return !!a;
141-
}).join('/').replace(/\/+/g, '/');
146+
var retSegs = [
147+
args.filter(function filter(a) {
148+
return !!a;
149+
}).join('/').replace(/\/+/g, '/')
150+
];
151+
152+
// Only join the query string if it exists so we don't have trailing a '?'
153+
// on every request
154+
lastSegs[1] && retSegs.push(lastSegs[1]);
155+
156+
return retSegs.join('?')
142157
};

test/lib-http-proxy-common-test.js

+9
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,15 @@ describe('lib/http-proxy/common.js', function () {
202202

203203
expect(outgoing.path).to.eql('/forward/static/path');
204204
})
205+
206+
it('should not modify the query string', function () {
207+
var outgoing = {};
208+
common.setupOutgoing(outgoing, {
209+
target: { path: '/forward' },
210+
}, { url: '/?foo=bar//&target=http://foobar.com/' });
211+
212+
expect(outgoing.path).to.eql('/forward/?foo=bar//&target=http://foobar.com/');
213+
})
205214
});
206215

207216
describe('#setupSocket', function () {

0 commit comments

Comments
 (0)