Skip to content

Commit 0dbdd29

Browse files
committed
move repetitive code for check if set strict transport security need to be skipped to trait
1 parent 82c09ac commit 0dbdd29

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

src/HttpsTrait.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
namespace ForceHttpsModule;
44

5+
use Psr\Http\Message\ResponseInterface;
56
use Zend\Router\RouteMatch;
67
use Zend\Expressive\Router\RouteResult;
8+
use Zend\Http\PhpEnvironment\Response;
79

810
trait HttpsTrait
911
{
@@ -40,6 +42,25 @@ private function isGoingToBeForcedToHttps($match)
4042
return true;
4143
}
4244

45+
/**
46+
* Check if Setup Strict-Transport-Security need to be skipped.
47+
*
48+
* @param string $uriScheme
49+
* @param RouteMatch|RouteResult $match
50+
* @param Response|ResponseInterface $response
51+
*
52+
* @return bool
53+
*/
54+
private function isSkippedHttpStrictTransportSecurity($uriScheme, $match, $response)
55+
{
56+
return ! $this->isSchemeHttps($uriScheme) ||
57+
! $this->isGoingToBeForcedToHttps($match) ||
58+
! isset(
59+
$this->config['strict_transport_security']['enable'],
60+
$this->config['strict_transport_security']['value']
61+
);
62+
}
63+
4364
/**
4465
* Validate Scheme and Forced Https Config
4566
*

src/Listener/ForceHttps.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,7 @@ public function attach(EventManagerInterface $events, $priority = 1)
4949
*/
5050
private function setHttpStrictTransportSecurity($uriScheme, $match, Response $response)
5151
{
52-
if (
53-
! $this->isSchemeHttps($uriScheme) ||
54-
! $this->isGoingToBeForcedToHttps($match) ||
55-
! isset(
56-
$this->config['strict_transport_security']['enable'],
57-
$this->config['strict_transport_security']['value']
58-
)
59-
) {
52+
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $match, $response)) {
6053
return $response;
6154
}
6255

src/Middleware/ForceHttps.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,7 @@ public function __construct(array $config, RouterInterface $router)
3838
*/
3939
private function setHttpStrictTransportSecurity($uriScheme, RouteResult $match, ResponseInterface $response)
4040
{
41-
if (
42-
! $this->isSchemeHttps($uriScheme) ||
43-
! $this->isGoingToBeForcedToHttps($match) ||
44-
! isset(
45-
$this->config['strict_transport_security']['enable'],
46-
$this->config['strict_transport_security']['value']
47-
)
48-
) {
41+
if ($this->isSkippedHttpStrictTransportSecurity($uriScheme, $match, $response)) {
4942
return $response;
5043
}
5144

0 commit comments

Comments
 (0)