Skip to content

Commit ec92719

Browse files
committed
add www. prefix for already https as well when previous uri doesnot has www. prefix for configured add_www_prefix
1 parent 0dbdd29 commit ec92719

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

src/HttpsTrait.php

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,23 +61,6 @@ private function isSkippedHttpStrictTransportSecurity($uriScheme, $match, $respo
6161
);
6262
}
6363

64-
/**
65-
* Validate Scheme and Forced Https Config
66-
*
67-
* @param string $uriScheme
68-
* @param RouteMatch|RouteResult $match
69-
*
70-
* @return bool
71-
*/
72-
private function validateSchemeAndToBeForcedHttpsConfig($uriScheme, $match)
73-
{
74-
if ($this->isSchemeHttps($uriScheme) || ! $this->isGoingToBeForcedToHttps($match)) {
75-
return false;
76-
}
77-
78-
return true;
79-
}
80-
8164
/**
8265
* Add www. prefix when required in the config
8366
*

src/Listener/ForceHttps.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@ public function forceHttpsScheme(MvcEvent $e)
8787

8888
$routeMatch = $e->getRouteMatch();
8989
$response = $this->setHttpStrictTransportSecurity($uriScheme, $routeMatch, $response);
90-
if (! $this->validateSchemeAndToBeForcedHttpsConfig($uriScheme, $routeMatch)) {
90+
if (! $this->isGoingToBeForcedToHttps($routeMatch)) {
9191
return;
9292
}
9393

94+
if ($this->isSchemeHttps($uriScheme)) {
95+
$uriString = $uri->toString();
96+
$httpsRequestUri = $this->withWwwPrefixWhenRequired($uriString);
97+
if ($uriString === $httpsRequestUri) {
98+
return;
99+
}
100+
}
101+
94102
$httpsRequestUri = $this->withWwwPrefixWhenRequired($uri->setScheme('https')->toString());
95103

96104
// 307 keeps headers, request method, and request body

src/Middleware/ForceHttps.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,18 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
6262
$uriScheme = $uri->getScheme();
6363

6464
$response = $this->setHttpStrictTransportSecurity($uriScheme, $match, $response);
65-
if (! $this->validateSchemeAndToBeForcedHttpsConfig($uriScheme, $match)) {
65+
if (! $this->isGoingToBeForcedToHttps($match)) {
6666
return $next($request, $response);
6767
}
6868

69+
if ($this->isSchemeHttps($uriScheme)) {
70+
$uriString = $uri->__toString();
71+
$httpsRequestUri = $this->withWwwPrefixWhenRequired($uriString);
72+
if ($uriString === $httpsRequestUri) {
73+
return $next($request, $response);
74+
}
75+
}
76+
6977
$newUri = $uri->withScheme('https');
7078
$httpsRequestUri = $this->withWwwPrefixWhenRequired($newUri->__toString());
7179

0 commit comments

Comments
 (0)