@@ -667,51 +667,51 @@ pub fn Bun__fetch_(
667667 break :extract_proxy buffer ;
668668 }
669669 // Handle object format: proxy: { url: "http://proxy.example.com:8080", headers?: Headers }
670+ // If the proxy object doesn't have a 'url' property, ignore it.
671+ // This handles cases like passing a URL object directly as proxy (which has 'href' not 'url').
670672 if (proxy_arg .isObject ()) {
671673 // Get the URL from the proxy object
672- const proxy_url_arg = try proxy_arg .get (globalThis , "url" );
673- if (proxy_url_arg == null or proxy_url_arg .? .isUndefinedOrNull ()) {
674- const err = ctx .toTypeError (.INVALID_ARG_VALUE , "fetch() proxy object requires a 'url' property" , .{});
675- is_error = true ;
676- return JSPromise .dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM (globalThis , err );
677- }
678- if (proxy_url_arg .? .isString () and try proxy_url_arg .? .getLength (ctx ) > 0 ) {
679- var href = try jsc .URL .hrefFromJS (proxy_url_arg .? , globalThis );
680- if (href .tag == .Dead ) {
681- const err = ctx .toTypeError (.INVALID_ARG_VALUE , "fetch() proxy URL is invalid" , .{});
682- is_error = true ;
683- return JSPromise .dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM (globalThis , err );
684- }
685- defer href .deref ();
686- const buffer = try std .fmt .allocPrint (allocator , "{s}{f}" , .{ url_proxy_buffer , href });
687- url = ZigURL .parse (buffer [0.. url .href .len ]);
688- if (url .isFile ()) {
689- url_type = URLType .file ;
690- } else if (url .isBlob ()) {
691- url_type = URLType .blob ;
692- }
674+ if (try proxy_arg .get (globalThis , "url" )) | proxy_url_arg | {
675+ if (! proxy_url_arg .isUndefinedOrNull ()) {
676+ if (proxy_url_arg .isString () and try proxy_url_arg .getLength (ctx ) > 0 ) {
677+ var href = try jsc .URL .hrefFromJS (proxy_url_arg , globalThis );
678+ if (href .tag == .Dead ) {
679+ const err = ctx .toTypeError (.INVALID_ARG_VALUE , "fetch() proxy URL is invalid" , .{});
680+ is_error = true ;
681+ return JSPromise .dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM (globalThis , err );
682+ }
683+ defer href .deref ();
684+ const buffer = try std .fmt .allocPrint (allocator , "{s}{f}" , .{ url_proxy_buffer , href });
685+ url = ZigURL .parse (buffer [0.. url .href .len ]);
686+ if (url .isFile ()) {
687+ url_type = URLType .file ;
688+ } else if (url .isBlob ()) {
689+ url_type = URLType .blob ;
690+ }
693691
694- proxy = ZigURL .parse (buffer [url .href .len .. ]);
695- allocator .free (url_proxy_buffer );
696- url_proxy_buffer = buffer ;
697-
698- // Get the headers from the proxy object (optional)
699- if (try proxy_arg .get (globalThis , "headers" )) | headers_value | {
700- if (! headers_value .isUndefinedOrNull ()) {
701- if (headers_value .as (FetchHeaders )) | fetch_hdrs | {
702- proxy_headers = Headers .from (fetch_hdrs , allocator , .{}) catch | err | bun .handleOom (err );
703- } else if (try FetchHeaders .createFromJS (ctx , headers_value )) | fetch_hdrs | {
704- defer fetch_hdrs .deref ();
705- proxy_headers = Headers .from (fetch_hdrs , allocator , .{}) catch | err | bun .handleOom (err );
692+ proxy = ZigURL .parse (buffer [url .href .len .. ]);
693+ allocator .free (url_proxy_buffer );
694+ url_proxy_buffer = buffer ;
695+
696+ // Get the headers from the proxy object (optional)
697+ if (try proxy_arg .get (globalThis , "headers" )) | headers_value | {
698+ if (! headers_value .isUndefinedOrNull ()) {
699+ if (headers_value .as (FetchHeaders )) | fetch_hdrs | {
700+ proxy_headers = Headers .from (fetch_hdrs , allocator , .{}) catch | err | bun .handleOom (err );
701+ } else if (try FetchHeaders .createFromJS (ctx , headers_value )) | fetch_hdrs | {
702+ defer fetch_hdrs .deref ();
703+ proxy_headers = Headers .from (fetch_hdrs , allocator , .{}) catch | err | bun .handleOom (err );
704+ }
705+ }
706706 }
707+
708+ break :extract_proxy url_proxy_buffer ;
709+ } else {
710+ const err = ctx .toTypeError (.INVALID_ARG_VALUE , "fetch() proxy.url must be a non-empty string" , .{});
711+ is_error = true ;
712+ return JSPromise .dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM (globalThis , err );
707713 }
708714 }
709-
710- break :extract_proxy url_proxy_buffer ;
711- } else {
712- const err = ctx .toTypeError (.INVALID_ARG_VALUE , "fetch() proxy.url must be a non-empty string" , .{});
713- is_error = true ;
714- return JSPromise .dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM (globalThis , err );
715715 }
716716 }
717717 }
0 commit comments