Skip to content

Commit

Permalink
Merge branch 'code-308'
Browse files Browse the repository at this point in the history
Closes #4
  • Loading branch information
samsonasik committed Oct 13, 2017
2 parents 39f23cc + cb77e19 commit d424926
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@
],
"require":{
"php": "^5.6 || ^7.0",
"zendframework/zend-console": "^2.5"
"zendframework/zend-console": "^2.5",
"zendframework/zend-http": "^2.7 || ^3.0"
},
"require-dev": {
"kahlan/kahlan": "^3.0",
"satooshi/php-coveralls": "^1.0",
"zendframework/zend-http": "^2.5 || ^3.0",
"zendframework/zend-mvc": "^2.5 || ^3.0",
"zendframework/zend-expressive": "^1.0 || ^2.0"
},
Expand Down
6 changes: 3 additions & 3 deletions spec/Listener/ForceHttpsSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
allow($this->uri)->toReceive('setScheme')->with('https')->andReturn($this->uri);
allow($this->uri)->toReceive('toString')->andReturn('https://example.com/about');
allow($this->mvcEvent)->toReceive('getResponse')->andReturn($this->response);
allow($this->response)->toReceive('setStatusCode')->with(307)->andReturn($this->response);
allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response);
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
allow($this->response)->toReceive('send');

Expand Down Expand Up @@ -171,7 +171,7 @@
allow($this->uri)->toReceive('toString')->andReturn('https://example.com/about');
allow($this->mvcEvent)->toReceive('getResponse')->andReturn($this->response);
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Strict-Transport-Security: max-age=31536000');
allow($this->response)->toReceive('setStatusCode')->with(307)->andReturn($this->response);
allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response);
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
allow($this->response)->toReceive('send');

Expand Down Expand Up @@ -200,7 +200,7 @@
allow($this->uri)->toReceive('setScheme')->with('https')->andReturn($this->uri);
allow($this->uri)->toReceive('toString')->andReturn('https://example.com/about');
allow($this->mvcEvent)->toReceive('getResponse')->andReturn($this->response);
allow($this->response)->toReceive('setStatusCode')->with(307)->andReturn($this->response);
allow($this->response)->toReceive('setStatusCode')->with(308)->andReturn($this->response);
allow($this->response)->toReceive('getHeaders', 'addHeaderLine')->with('Location', 'https://example.com/about');
allow($this->response)->toReceive('send');

Expand Down
5 changes: 2 additions & 3 deletions src/Listener/ForceHttps.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ public function forceHttpsScheme(MvcEvent $e)
$httpsRequestUri = $this->withoutWwwPrefixWhenNotRequired($httpsRequestUri);
}

// 307 keeps headers, request method, and request body
// \Zend\Http\PhpEnvironment\Response doesn't support 308 yet
$response->setStatusCode(307);
// 308 keeps headers, request method, and request body
$response->setStatusCode(308);
$response->getHeaders()
->addHeaderLine('Location', $httpsRequestUri);
$response->send();
Expand Down
1 change: 0 additions & 1 deletion src/Middleware/ForceHttps.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public function __invoke(ServerRequestInterface $request, ResponseInterface $res
}

// 308 keeps headers, request method, and request body
// \Zend\Diactoros\Response already support 308
$response = $response->withStatus(308);
$response = $response->withHeader('Location', $httpsRequestUri);

Expand Down

0 comments on commit d424926

Please sign in to comment.