Skip to content

do not modify the query string #733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 19 additions & 4 deletions lib/http-proxy/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
if (options.changeOrigin) {
outgoing.headers.host = outgoing.host;
}

return outgoing;
};

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

common.urlJoin = function() {
var args = Array.prototype.slice.call(arguments);

// We do not want to mess with the query string. All we want to touch is the path.
var lastIndex = args.length-1;
var last = args[lastIndex]
var lastSegs = last.split('?')
args[lastIndex] = lastSegs[0]

// Join all strings, but remove empty strings so we don't get extra slashes from
// joining e.g. ['', 'am']
return args.filter(function filter(a) {
return !!a;
}).join('/').replace(/\/+/g, '/');
var retSegs = [
args.filter(function filter(a) {
return !!a;
}).join('/').replace(/\/+/g, '/')
];

// Only join the query string if it exists so we don't have trailing a '?'
// on every request
lastSegs[1] && retSegs.push(lastSegs[1]);

return retSegs.join('?')
};
9 changes: 9 additions & 0 deletions test/lib-http-proxy-common-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,15 @@ describe('lib/http-proxy/common.js', function () {

expect(outgoing.path).to.eql('/forward/static/path');
})

it('should not modify the query string', function () {
var outgoing = {};
common.setupOutgoing(outgoing, {
target: { path: '/forward' },
}, { url: '/?foo=bar//&target=http://foobar.com/' });

expect(outgoing.path).to.eql('/forward/?foo=bar//&target=http://foobar.com/');
})
});

describe('#setupSocket', function () {
Expand Down