Skip to content

Commit a1ed037

Browse files
committed
Route, SimpleRouter: by default keeps the currently used HTTP/HTTPS protocol (BC break) [Closes nette/nette#1196][Closes nette/routing#14]
1 parent f0724d6 commit a1ed037

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

src/Application/Routers/Route.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
385385

386386
if ($this->type !== self::HOST) {
387387
if ($this->lastRefUrl !== $refUrl) {
388-
$scheme = ($this->flags & self::SECURED ? 'https://' : 'http://');
388+
$scheme = ($this->flags & self::SECURED ? 'https://' : $refUrl->getScheme() . '://');
389389
$basePath = ($this->type === self::RELATIVE ? $refUrl->getBasePath() : '');
390390
$this->lastBaseUrl = $scheme . $refUrl->getAuthority() . $basePath;
391391
$this->lastRefUrl = $refUrl;
@@ -401,7 +401,7 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
401401
'%domain%' => isset($host[1]) ? "$host[1].$host[0]" : $host[0],
402402
'%sld%' => isset($host[1]) ? $host[1] : '',
403403
]);
404-
$url = ($this->flags & self::SECURED ? 'https:' : 'http:') . $url;
404+
$url = ($this->flags & self::SECURED ? 'https:' : $refUrl->getScheme() . ':') . $url;
405405
}
406406

407407
if (strpos($url, '//', 7) !== FALSE) {

src/Application/Routers/SimpleRouter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public function constructUrl(Application\Request $appRequest, Nette\Http\Url $re
115115
}
116116
}
117117

118-
$url = ($this->flags & self::SECURED ? 'https://' : 'http://') . $refUrl->getAuthority() . $refUrl->getPath();
118+
$url = ($this->flags & self::SECURED ? 'https://' : $refUrl->getScheme() . '://') . $refUrl->getAuthority() . $refUrl->getPath();
119119
$sep = ini_get('arg_separator.input');
120120
$query = http_build_query($params, '', $sep ? $sep[0] : '&');
121121
if ($query != '') { // intentionally ==

tests/Routers/Route.basic.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ testRouteIn($route, '/presenter', 'Presenter', [
6969
'id' => '',
7070
'action' => 'default',
7171
'test' => 'testvalue',
72-
], '/presenter/?test=testvalue', TRUE);
72+
], 'https://example.com/presenter/?test=testvalue', TRUE);

tests/Routers/Route.withAbsolutePath.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ testRouteIn($route, '/abc', 'Default', [
2828
'abspath' => 'abc',
2929
'action' => 'default',
3030
'test' => 'testvalue',
31-
], '/abc/?test=testvalue', TRUE);
31+
], 'https://example.com/abc/?test=testvalue', TRUE);

tests/Routers/Route.withHost.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ testRouteIn($route, '/abc', 'Default', [
3232
'path' => 'abc',
3333
'action' => 'default',
3434
'test' => 'testvalue',
35-
], '/abc?test=testvalue', TRUE);
35+
], 'https://example.com/abc?test=testvalue', TRUE);

tests/Routers/SimpleRouter.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,4 @@ Assert::same('http://nette.org/file.php?action=action&test=testvalue&presenter=m
4040

4141
$url = new Http\UrlScript('https://nette.org/file.php');
4242
$res = $router->constructUrl($req, $url);
43-
Assert::same('http://nette.org/file.php?action=action&test=testvalue&presenter=myPresenter', $res);
43+
Assert::same('https://nette.org/file.php?action=action&test=testvalue&presenter=myPresenter', $res);

0 commit comments

Comments
 (0)