@@ -581,12 +581,34 @@ public function __toString(): string
581581 $ path = $ this ->getPath ();
582582 $ scheme = $ this ->getScheme ();
583583
584+ // If the hosts matches then assume this should be relative to baseURL
585+ [$ scheme , $ path ] = $ this ->changeSchemeAndPath ($ scheme , $ path );
586+
587+ return static ::createURIString (
588+ $ scheme ,
589+ $ this ->getAuthority (),
590+ $ path , // Absolute URIs should use a "/" for an empty path
591+ $ this ->getQuery (),
592+ $ this ->getFragment ()
593+ );
594+ }
595+
596+ /**
597+ * Change the path (and scheme) assuming URIs with the same host as baseURL
598+ * should be relative to the project's configuration.
599+ *
600+ * @deprecated This method will be deleted.
601+ */
602+ private function changeSchemeAndPath (string $ scheme , string $ path ): array
603+ {
584604 // Check if this is an internal URI
585605 $ config = config ('App ' );
586606 $ baseUri = new self ($ config ->baseURL );
587607
588- // If the hosts matches then assume this should be relative to baseURL
589- if ($ this ->getHost () === $ baseUri ->getHost ()) {
608+ if (
609+ substr ($ this ->getScheme (), 0 , 4 ) === 'http '
610+ && $ this ->getHost () === $ baseUri ->getHost ()
611+ ) {
590612 // Check for additional segments
591613 $ basePath = trim ($ baseUri ->getPath (), '/ ' ) . '/ ' ;
592614 $ trimPath = ltrim ($ path , '/ ' );
@@ -601,13 +623,7 @@ public function __toString(): string
601623 }
602624 }
603625
604- return static ::createURIString (
605- $ scheme ,
606- $ this ->getAuthority (),
607- $ path , // Absolute URIs should use a "/" for an empty path
608- $ this ->getQuery (),
609- $ this ->getFragment ()
610- );
626+ return [$ scheme , $ path ];
611627 }
612628
613629 /**
0 commit comments