fix(fetch): ignore proxy object without url property (#25414)

## Summary
- When a URL object is passed as the proxy option, or when a proxy
object lacks a "url" property, ignore it instead of throwing an error
- This fixes a regression introduced in 1.3.4 where libraries like taze
that pass URL objects as proxy values would fail

## Test plan
- Added test: "proxy as URL object should be ignored (no url property)"
- passes a URL object directly as proxy
- Updated test: "proxy object without url is ignored (regression
#25413)" - proxy object with headers but no url
- Updated test: "proxy object with null url is ignored (regression
#25413)" - proxy object where url is null
- All 29 proxy tests pass

Fixes #25413

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
This commit is contained in:
robobun
2025-12-09 12:31:45 -08:00
committed by GitHub
parent 2028e21d60
commit 8dc084af5f
2 changed files with 82 additions and 61 deletions

View File

@@ -500,29 +500,32 @@ describe("proxy object format with headers", () => {
}
});
test("proxy object without url throws error", async () => {
await expect(
fetch(httpServer.url, {
method: "GET",
proxy: {
headers: { "X-Test": "value" },
} as any,
keepalive: false,
}),
).rejects.toThrow("fetch() proxy object requires a 'url' property");
test("proxy object without url is ignored (regression #25413)", async () => {
// When proxy object doesn't have a 'url' property, it should be ignored
// This ensures compatibility with libraries that pass URL objects as proxy
const response = await fetch(httpServer.url, {
method: "GET",
proxy: {
headers: { "X-Test": "value" },
} as any,
keepalive: false,
});
expect(response.ok).toBe(true);
expect(response.status).toBe(200);
});
test("proxy object with null url throws error", async () => {
await expect(
fetch(httpServer.url, {
method: "GET",
proxy: {
url: null,
headers: { "X-Test": "value" },
} as any,
keepalive: false,
}),
).rejects.toThrow("fetch() proxy object requires a 'url' property");
test("proxy object with null url is ignored (regression #25413)", async () => {
// When proxy.url is null, the proxy object should be ignored
const response = await fetch(httpServer.url, {
method: "GET",
proxy: {
url: null,
headers: { "X-Test": "value" },
} as any,
keepalive: false,
});
expect(response.ok).toBe(true);
expect(response.status).toBe(200);
});
test("proxy object with empty string url throws error", async () => {
@@ -699,4 +702,22 @@ describe("proxy object format with headers", () => {
await once(proxyServerWithCapture, "close");
}
});
test("proxy as URL object should be ignored (no url property)", async () => {
// This tests the regression from #25413
// When a URL object is passed as proxy, it should be ignored (no error)
// because URL objects don't have a "url" property - they have "href"
const proxyUrl = new URL(httpProxyServer.url);
// Passing a URL object as proxy should NOT throw an error
// It should just be ignored since there's no "url" string property
const response = await fetch(httpServer.url, {
method: "GET",
proxy: proxyUrl as any,
keepalive: false,
});
// The request should succeed (without proxy, since URL object is ignored)
expect(response.ok).toBe(true);
expect(response.status).toBe(200);
});
});