Skip to content

Commit 7759c94

Browse files
pi0claude
andcommitted
fix(proxy): ensure leading slash on toProxy outgoing path
The `toProxy` code path was passing `req.url` directly without a leading `/`, causing `joinURL` to return the raw URL without the expected prefix. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent d0cb298 commit 7759c94

2 files changed

Lines changed: 4 additions & 7 deletions

File tree

‎src/_utils.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ export function setupOutgoing(
107107
: "";
108108

109109
const parsed = new URL(req.url!, "http://localhost");
110-
let outgoingPath = options.toProxy ? req.url : parsed.pathname + parsed.search || "";
110+
let outgoingPath = options.toProxy ? "/" + req.url : parsed.pathname + parsed.search || "";
111111

112112
//
113113
// Remark: ignorePath will just straight up ignore whatever the request's

‎test/_utils.test.ts‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import * as common from "../src/_utils.ts";
44
// Source: https://github.com/http-party/node-http-proxy/blob/master/test/lib-http-proxy-common-test.js
55

66
// Difference from http-proxy is that we always ensure leading slash on path
7-
// TODO: Couple of tests (wrongly?) failing and marked as todo
87

98
describe("lib/http-proxy/common.js", () => {
109
describe("#setupOutgoing", () => {
@@ -272,7 +271,7 @@ describe("lib/http-proxy/common.js", () => {
272271
//
273272
// This is the proper failing test case for the common.join problem
274273
//
275-
it.todo("should correctly format the toProxy URL", () => {
274+
it("should correctly format the toProxy URL", () => {
276275
const outgoing = {} as any;
277276
const google = "https://google.com";
278277
common.setupOutgoing(
@@ -287,8 +286,7 @@ describe("lib/http-proxy/common.js", () => {
287286
expect(outgoing.path).to.eql("/" + google);
288287
});
289288

290-
// eslint-disable-next-line no-useless-escape
291-
it.todo("should not replace :\ to :\\ when no https word before", () => {
289+
it("should not replace :\\ to :\\\\ when no https word before", () => {
292290
const outgoing = {} as any;
293291
const google = "https://google.com:/join/join.js";
294292
common.setupOutgoing(
@@ -303,8 +301,7 @@ describe("lib/http-proxy/common.js", () => {
303301
expect(outgoing.path).to.eql("/" + google);
304302
});
305303

306-
// eslint-disable-next-line no-useless-escape
307-
it.todo("should not replace :\ to :\\ when no http word before", () => {
304+
it("should not replace :\\ to \\\\ when no http word before", () => {
308305
const outgoing = {} as any;
309306
const google = "http://google.com:/join/join.js";
310307
common.setupOutgoing(

0 commit comments

Comments
 (0)