2626 *
2727 * @internal Outside the framework this should not be used directly.
2828 *
29- * @param array|string $relativePath URI string or array of URI segments
29+ * @param array|string $relativePath URI string or array of URI segments.
30+ * May include queries or fragments.
3031 * @param App|null $config Alternative Config to use
3132 * @param bool $indexPage Whether to add the $indexPage value
3233 *
@@ -82,7 +83,14 @@ function _get_uri($relativePath = '', ?App $config = null, bool $indexPage = fal
8283 }
8384 }
8485
85- return new URI ($ url . $ relativePath );
86+ $ uri = new URI ($ url . $ relativePath );
87+
88+ // Check if the baseURL scheme needs to be coerced into its secure version
89+ if ($ config ->forceGlobalSecureRequests && $ uri ->getScheme () === 'http ' ) {
90+ $ uri ->setScheme ('https ' );
91+ }
92+
93+ return $ uri ;
8694 }
8795}
8896
@@ -157,12 +165,10 @@ function base_url($relativePath = '', ?string $scheme = null): string
157165 function current_url (bool $ returnObject = false , ?IncomingRequest $ request = null )
158166 {
159167 $ request ??= Services::request ();
168+ /** @var CLIRequest|IncomingRequest $request */
160169 $ routePath = $ request ->getPath ();
161170 $ currentURI = $ request ->getUri ();
162171
163- $ currentBaseURL = $ currentURI ->getBaseURL ();
164-
165- $ config = config ('App ' );
166172 $ relativePath = $ routePath ;
167173
168174 // Append queries and fragments
@@ -173,18 +179,7 @@ function current_url(bool $returnObject = false, ?IncomingRequest $request = nul
173179 $ relativePath .= '# ' . $ fragment ;
174180 }
175181
176- // Check for an index page
177- $ indexPage = '' ;
178- if ($ config ->indexPage !== '' ) {
179- $ indexPage = $ config ->indexPage ;
180-
181- // Check if we need a separator
182- if ($ relativePath !== '' && $ relativePath [0 ] !== '/ ' && $ relativePath [0 ] !== '? ' ) {
183- $ indexPage .= '/ ' ;
184- }
185- }
186-
187- $ uri = new URI ($ currentBaseURL . $ indexPage . $ relativePath );
182+ $ uri = _get_uri ($ relativePath , null , true );
188183
189184 return $ returnObject ? $ uri : URI ::createURIString ($ uri ->getScheme (), $ uri ->getAuthority (), $ uri ->getPath ());
190185 }
0 commit comments