@@ -294,6 +294,10 @@ async function stream2(
294294 if ( options . forward ) {
295295 const outgoingOptions = common . setupOutgoing ( options . ssl || { } , options , req , "forward" ) ;
296296 const requestOptions = prepareRequest ( outgoingOptions ) ;
297+ let targetUrl = new URL ( outgoingOptions . url ) . origin + outgoingOptions . path ;
298+ if ( targetUrl . startsWith ( "ws" ) ) {
299+ targetUrl = targetUrl . replace ( "ws" , "http" ) ;
300+ }
297301
298302 // Call onBeforeRequest callback before making the forward request
299303 if ( fetchOptions . onBeforeRequest ) {
@@ -306,7 +310,7 @@ async function stream2(
306310 }
307311
308312 try {
309- const result = await customFetch ( new URL ( outgoingOptions . url ) . origin + outgoingOptions . path , requestOptions ) ;
313+ const result = await customFetch ( targetUrl , requestOptions ) ;
310314
311315 // Call onAfterResponse callback for forward requests (though they typically don't expect responses)
312316 if ( fetchOptions . onAfterResponse ) {
@@ -338,6 +342,10 @@ async function stream2(
338342
339343 const outgoingOptions = common . setupOutgoing ( options . ssl || { } , options , req ) ;
340344 const requestOptions = prepareRequest ( outgoingOptions ) ;
345+ let targetUrl = new URL ( outgoingOptions . url ) . origin + outgoingOptions . path ;
346+ if ( targetUrl . startsWith ( "ws" ) ) {
347+ targetUrl = targetUrl . replace ( "ws" , "http" ) ;
348+ }
341349
342350 // Call onBeforeRequest callback before making the request
343351 if ( fetchOptions . onBeforeRequest ) {
@@ -350,7 +358,7 @@ async function stream2(
350358 }
351359
352360 try {
353- const response = await customFetch ( new URL ( outgoingOptions . url ) . origin + outgoingOptions . path , requestOptions ) ;
361+ const response = await customFetch ( targetUrl , requestOptions ) ;
354362
355363 // Call onAfterResponse callback after receiving the response
356364 if ( fetchOptions . onAfterResponse ) {
0 commit comments