Skip to content

Commit f7f1ff9

Browse files
authored
Merge pull request #32 from sapphi-red/fix/use-invalid-domain-as-base-in-to-url
fix: use invalid domain as base in `toURL`
2 parents 2082faa + 629e437 commit f7f1ff9

File tree

4 files changed

+13
-13
lines changed

4 files changed

+13
-13
lines changed

lib/http-proxy/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,10 @@ export function toURL(url: URL | urllib.Url | ProxyTargetDetailed | string | und
291291
if (url.startsWith("//")) {
292292
// special case -- this would be viewed as a this is a "network-path reference",
293293
// so we explicitly prefix with our http schema. See
294-
url = `http://dummy.org${url}`;
294+
url = `http://base.invalid${url}`;
295295
}
296296
// urllib.Url is deprecated but we support it by converting to URL
297-
return new URL(url, "http://dummy.org");
297+
return new URL(url, "http://base.invalid");
298298
}
299299

300300
// vendor simplified version of https://www.npmjs.com/package/requires-port to

lib/test/http/reverse-proxy.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe("Reverse proxying -- create a server that...", () => {
2626
server = http
2727
.createServer((req, res) => {
2828
log("Receiving reverse proxy request for:", req.url);
29-
const urlObj = new URL(req.url ?? "", "http://dummy.org");
29+
const urlObj = new URL(req.url ?? "", "http://base.invalid");
3030
const target = urlObj.origin;
3131
proxy.web(req, res, { target, secure: false });
3232
})

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ describe("#setupOutgoing", () => {
298298
setupOutgoing(
299299
outgoing,
300300
{
301-
target: new URL("http://dummy.org/some-path?a=1&b=2"),
301+
target: new URL("http://base.invalid/some-path?a=1&b=2"),
302302
},
303303
{ url: "/src?s=1" },
304304
);
@@ -311,7 +311,7 @@ describe("#setupOutgoing", () => {
311311
setupOutgoing(
312312
outgoing,
313313
{
314-
target: new URL("http://dummy.org/some-path?a=1&b=2"),
314+
target: new URL("http://base.invalid/some-path?a=1&b=2"),
315315
ignorePath: true,
316316
},
317317
{ url: "/src?s=1" },
@@ -329,7 +329,7 @@ describe("#setupOutgoing", () => {
329329
setupOutgoing(
330330
outgoing,
331331
{
332-
target: new URL("http://sometarget.com:80", "http://dummy.org"),
332+
target: new URL("http://sometarget.com:80", "http://base.invalid"),
333333
toProxy: true,
334334
},
335335
{ url: google },
@@ -344,7 +344,7 @@ describe("#setupOutgoing", () => {
344344
setupOutgoing(
345345
outgoing,
346346
{
347-
target: new URL("http://sometarget.com:80", "http://dummy.org"),
347+
target: new URL("http://sometarget.com:80", "http://base.invalid"),
348348
toProxy: true,
349349
},
350350
{ url: google },
@@ -359,7 +359,7 @@ describe("#setupOutgoing", () => {
359359
setupOutgoing(
360360
outgoing,
361361
{
362-
target: new URL("http://sometarget.com:80", "http://dummy.org"),
362+
target: new URL("http://sometarget.com:80", "http://base.invalid"),
363363
toProxy: true,
364364
},
365365
{ url: google },
@@ -375,7 +375,7 @@ describe("#setupOutgoing", () => {
375375
setupOutgoing(
376376
outgoing,
377377
{
378-
target: new URL(myEndpoint, "http://dummy.org"),
378+
target: new URL(myEndpoint, "http://base.invalid"),
379379
ignorePath: true,
380380
},
381381
{ url: "/more/crazy/pathness" },
@@ -390,7 +390,7 @@ describe("#setupOutgoing", () => {
390390
setupOutgoing(
391391
outgoing,
392392
{
393-
target: new URL(myEndpoint, "http://dummy.org"),
393+
target: new URL(myEndpoint, "http://base.invalid"),
394394
ignorePath: true,
395395
prependPath: false,
396396
},
@@ -408,7 +408,7 @@ describe("#setupOutgoing", () => {
408408
setupOutgoing(
409409
outgoing,
410410
{
411-
target: new URL(myEndpoint, "http://dummy.org"),
411+
target: new URL(myEndpoint, "http://base.invalid"),
412412
changeOrigin: true,
413413
},
414414
{ url: "/" },
@@ -475,7 +475,7 @@ describe("#setupOutgoing", () => {
475475
setupOutgoing(
476476
outgoing,
477477
{
478-
target: new URL("https://whooooo.com", "http://dummy.org"),
478+
target: new URL("https://whooooo.com", "http://base.invalid"),
479479
method: "POST",
480480
},
481481
{ method: "GET", url: "" },

lib/test/lib/http-proxy-passes-web-incoming.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ describe("#followRedirects", () => {
626626
const source = http
627627
.createServer((req, res) => {
628628
if (
629-
new URL(req.url ?? "", "http://dummy.org").pathname === "/redirect"
629+
new URL(req.url ?? "", "http://base.invalid").pathname === "/redirect"
630630
) {
631631
res.writeHead(200, { "Content-Type": "text/plain" });
632632
res.end("ok");

0 commit comments

Comments
 (0)