8000 Use better default ports in urlRedirectAction · symfony/symfony@64b54dc · GitHub
[go: up one dir, main page]

Skip to content

Commit 64b54dc

Browse files
committed
Use better default ports in urlRedirectAction
1 parent 64216f2 commit 64b54dc

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/Symfony/Bundle/FrameworkBundle/Controller/RedirectController.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function redirectAction($route, $permanent = false)
6464
*
6565
* @return Response A Response instance
6666
*/
67-
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = 80, $httpsPort = 443)
67+
public function urlRedirectAction($path, $permanent = false, $scheme = null, $httpPort = null, $httpsPort = null)
6868
{
6969
if (!$path) {
7070
return new Response(null, 410);
@@ -88,10 +88,28 @@ public function urlRedirectAction($path, $permanent = false, $scheme = null, $ht
8888
}
8989

9090
$port = '';
91-
if ('http' === $scheme && 80 != $httpPort) {
92-
$port = ':'.$httpPort;
93-
} elseif ('https' === $scheme && 443 != $httpsPort) {
94-
$port = ':'.$httpsPort;
91+
if ('http' === $scheme) {
92+
if ($httpPort == null) {
93+
if ('http' === $request->getScheme()) {
94+
$httpPort = $request->getPort();
95+
} else {
96+
$httpPort = $this->container->getParameter('request_listener.http_port');
97+
}
98+
}
99+
if ($httpPort != null && $httpPort != 80) {
100+
$port = ":$httpPort";
101+
}
102+
} else if ('https' === $scheme) {
103+
if ($httpsPort == null) {
104+
if ('https' === $request->getScheme()) {
105+
$httpsPort = $request->getPort();
106+
} else {
107+
$httpsPort = $this->container->getParameter('request_listener.https_port');
108+
}
109+
}
110+
if ($httpsPort != null && $httpsPort != 443) {
111+
$port = ":$httpsPort";
112+
}
95113
}
96114

97115
$url = $scheme.'://'.$request->getHost().$port.$request->getBaseUrl().$path.$qs;

0 commit comments

Comments
 (0)
0