Skip to content
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

Simplify outgoing path computation when there is no merging of paths #1164

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/http-proxy/common.js
Expand Up @@ -95,7 +95,14 @@ common.setupOutgoing = function(outgoing, options, req, forward) {
//
outgoingPath = !options.ignorePath ? outgoingPath : '';

outgoing.path = common.urlJoin(targetPath, outgoingPath);

if (!targetPath) {
outgoing.path = outgoingPath;
} else if (!outgoingPath) {
outgoing.path = targetPath;
} else {
outgoing.path = common.urlJoin(targetPath, outgoingPath);
}

if (options.changeOrigin) {
outgoing.headers.host =
Expand Down
11 changes: 11 additions & 0 deletions test/lib-http-proxy-common-test.js
Expand Up @@ -275,6 +275,17 @@ describe('lib/http-proxy/common.js', function () {
expect(outgoing.path).to.eql('/some/crazy/path/whoooo');
});

it('should ignore the path of the `req.url` passed in but use the target path', function () {
var outgoing = {};
var myEndpoint = 'https://whatever.com/some/crazy/path/whoooo?hello=1&hello=https://2.a.a&ola=https://a.c.c';
common.setupOutgoing(outgoing, {
target: url.parse(myEndpoint),
ignorePath: true
}, { url: '/more/crazy/pathness' });

expect(outgoing.path).to.eql('/some/crazy/path/whoooo?hello=1&hello=https://2.a.a&ola=https://a.c.c');
});

it('and prependPath: false, it should ignore path of target and incoming request', function () {
var outgoing = {};
var myEndpoint = 'https://whatever.com/some/crazy/path/whoooo';
Expand Down