@@ -96,6 +96,9 @@ class Route implements Application\IRouter
9696 /** @var int HOST, PATH, RELATIVE */
9797 private $ type ;
9898
99+ /** @var string http | https */
100+ private $ scheme ;
101+
99102 /** @var int */
100103 private $ flags ;
101104
@@ -136,8 +139,9 @@ public function __construct($mask, $metadata = [], $flags = 0)
136139 $ this ->setMask ($ mask , $ metadata );
137140 if (static ::$ defaultFlags ) {
138141 trigger_error ('Route::$defaultFlags is deprecated, router by default keeps the used protocol. ' , E_USER_DEPRECATED );
139- } elseif ($ this ->type !== self ::HOST && $ flags & self ::SECURED ) {
140- trigger_error ('Router::SECURED is deprecated for routes without host, router by default keeps the used protocol. ' , E_USER_DEPRECATED );
142+ } elseif ($ flags & self ::SECURED ) {
143+ trigger_error ('Router::SECURED is deprecated, specify scheme in mask. ' , E_USER_DEPRECATED );
144+ $ this ->scheme = 'https ' ;
141145 }
142146 }
143147
@@ -397,18 +401,18 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
397401 '%domain% ' => isset ($ parts [1 ]) ? "$ parts [1 ]. $ parts [0 ]" : $ parts [0 ],
398402 '%sld% ' => isset ($ parts [1 ]) ? $ parts [1 ] : '' ,
399403 ]);
400- if ($ this ->flags & self :: SECURED ) {
401- $ url = ' https : ' . $ url ;
404+ if ($ this ->scheme ) {
405+ $ url = $ this -> scheme . ' : ' . $ url ;
402406 } elseif (strncmp ($ url , "// $ host/ " , strlen ($ host ) + 3 ) === 0 ) {
403407 $ url = $ refUrl ->getScheme () . ': ' . $ url ;
404408 } else {
405409 $ url = 'http: ' . $ url ;
406410 }
407411 } else {
408412 if ($ this ->lastRefUrl !== $ refUrl ) {
409- $ scheme = ($ this ->flags & self :: SECURED ? ' https:// ' : $ refUrl ->getScheme () . ' :// ' );
413+ $ scheme = ($ this ->scheme ?: $ refUrl ->getScheme ());
410414 $ basePath = ($ this ->type === self ::RELATIVE ? $ refUrl ->getBasePath () : '' );
411- $ this ->lastBaseUrl = $ scheme . $ refUrl ->getAuthority () . $ basePath ;
415+ $ this ->lastBaseUrl = $ scheme . ' :// ' . $ refUrl ->getAuthority () . $ basePath ;
412416 $ this ->lastRefUrl = $ refUrl ;
413417 }
414418 $ url = $ this ->lastBaseUrl . $ url ;
@@ -444,8 +448,9 @@ private function setMask($mask, array $metadata)
444448 $ this ->mask = $ mask ;
445449
446450 // detect '//host/path' vs. '/abs. path' vs. 'relative path'
447- if (substr ( $ mask , 0 , 2 ) === ' // ' ) {
451+ if (preg_match ( ' #(?:(https?):)?(//.*)#A ' , $ mask , $ m ) ) {
448452 $ this ->type = self ::HOST ;
453+ list (, $ this ->scheme , $ mask ) = $ m ;
449454
450455 } elseif (substr ($ mask , 0 , 1 ) === '/ ' ) {
451456 $ this ->type = self ::PATH ;
0 commit comments