Skip to content
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
2 changes: 1 addition & 1 deletion lib/http-proxy/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export function setupOutgoing(

// target if defined is a URL object so has attribute "pathname", not "path".
const targetPath =
target && options.prependPath !== false && 'pathname' in target ? getPath(target.pathname) : "/";
target && options.prependPath !== false && 'pathname' in target ? getPath(`${target.pathname}${target.search ?? ""}`) : "/";

let outgoingPath = options.toProxy ? req.url : getPath(req.url);

Expand Down
27 changes: 27 additions & 0 deletions lib/test/lib/http-proxy-common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,33 @@ describe("#setupOutgoing", () => {
expect(outgoing.path).toEqual("/forward/src?f=1&s=1");
});

it("target path is URL and has query string", () => {
const outgoing: any = {};
setupOutgoing(
outgoing,
{
target: new URL("http://dummy.org/some-path?a=1&b=2"),
},
{ url: "/src?s=1" },
);

expect(outgoing.path).toEqual("/some-path/src?a=1&b=2&s=1");
});

it("target path is URL and has query string with ignorePath", () => {
const outgoing: any = {};
setupOutgoing(
outgoing,
{
target: new URL("http://dummy.org/some-path?a=1&b=2"),
ignorePath: true,
},
{ url: "/src?s=1" },
);

expect(outgoing.path).toEqual("/some-path?a=1&b=2");
});

//
// This is the proper failing test case for the common.join problem
//
Expand Down