1414use CodeIgniter \HTTP \Exceptions \HTTPException ;
1515use CodeIgniter \HTTP \Files \FileCollection ;
1616use CodeIgniter \HTTP \Files \UploadedFile ;
17+ use CodeIgniter \HTTP \URI ;
1718use Config \App ;
1819use Config \Services ;
1920use InvalidArgumentException ;
@@ -123,7 +124,7 @@ class IncomingRequest extends Request
123124 /**
124125 * Constructor
125126 *
126- * @param object $config
127+ * @param App $config
127128 * @param URI $uri
128129 * @param string|null $body
129130 * @param UserAgent $userAgent
@@ -149,7 +150,7 @@ public function __construct($config, URI $uri = null, $body = 'php://input', Use
149150
150151 $ this ->populateHeaders ();
151152
152- // Get our current URI.
153+ // Determine the current URI
153154 // NOTE: This WILL NOT match the actual URL in the browser since for
154155 // everything this cares about (and the router, etc) is the portion
155156 // AFTER the script name. So, if hosted in a sub-folder this will
@@ -158,6 +159,12 @@ public function __construct($config, URI $uri = null, $body = 'php://input', Use
158159
159160 $ this ->detectURI ($ config ->uriProtocol , $ config ->baseURL );
160161
162+ // Check if the baseURL scheme needs to be coerced into its secure version
163+ if ($ config ->forceGlobalSecureRequests && $ this ->uri ->getScheme () === 'http ' )
164+ {
165+ $ this ->uri ->setScheme ('https ' );
166+ }
167+
161168 $ this ->validLocales = $ config ->supportedLocales ;
162169
163170 $ this ->detectLocale ($ config );
@@ -610,11 +617,11 @@ protected function detectURI(string $protocol, string $baseURL)
610617
611618 // It's possible the user forgot a trailing slash on their
612619 // baseURL, so let's help them out.
613- $ baseURL = ! empty ( $ baseURL) ? rtrim ($ baseURL , '/ ' ) . '/ ' : $ baseURL ;
620+ $ baseURL = $ baseURL === '' ? $ baseURL : rtrim ($ baseURL , '/ ' ) . '/ ' ;
614621
615622 // Based on our baseURL provided by the developer
616623 // set our current domain name, scheme
617- if (! empty ( $ baseURL) )
624+ if ($ baseURL !== '' )
618625 {
619626 $ this ->uri ->setScheme (parse_url ($ baseURL , PHP_URL_SCHEME ));
620627 $ this ->uri ->setHost (parse_url ($ baseURL , PHP_URL_HOST ));
@@ -758,12 +765,9 @@ protected function parseRequestURI(): string
758765
759766 parse_str ($ _SERVER ['QUERY_STRING ' ], $ _GET );
760767
761- if ($ uri === '/ ' || $ uri === '' )
762- {
763- return '/ ' ;
764- }
768+ $ uri = URI ::removeDotSegments ($ uri );
765769
766- return $ this -> removeRelativeDirectory ($ uri );
770+ return ( $ uri === ' / ' || $ uri === '' ) ? ' / ' : ltrim ($ uri, ' / ' );
767771 }
768772
769773 //--------------------------------------------------------------------
@@ -793,7 +797,9 @@ protected function parseQueryString(): string
793797
794798 parse_str ($ _SERVER ['QUERY_STRING ' ], $ _GET );
795799
796- return $ this ->removeRelativeDirectory ($ uri );
800+ $ uri = URI ::removeDotSegments ($ uri );
801+
802+ return ($ uri === '/ ' || $ uri === '' ) ? '/ ' : ltrim ($ uri , '/ ' );
797803 }
798804
799805 //--------------------------------------------------------------------
@@ -806,22 +812,13 @@ protected function parseQueryString(): string
806812 * @param string $uri
807813 *
808814 * @return string
815+ *
816+ * @deprecated Use URI::removeDotSegments() directly
809817 */
810818 protected function removeRelativeDirectory (string $ uri ): string
811819 {
812- $ uris = [];
813- $ tok = strtok ($ uri , '/ ' );
814- while ($ tok !== false )
815- {
816- if ((! empty ($ tok ) || $ tok === '0 ' ) && $ tok !== '.. ' )
817- {
818- $ uris [] = $ tok ;
819- }
820- $ tok = strtok ('/ ' );
821- }
820+ $ uri = URI ::removeDotSegments ($ uri );
822821
823- return implode ( '/ ' , $ uris );
822+ return $ uri === '/ ' ? $ uri : ltrim ( $ uri , ' / ' );
824823 }
825-
826- // --------------------------------------------------------------------
827824}
0 commit comments