Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

`Response` should set status to 302 when 'location' passed to constru…

…ctor. Fixes #664.
  • Loading branch information...
commit 96bb8328dbef1c7bab1c60ab315aadd7c3ba4f83 1 parent c9cc84d
@nateabele nateabele authored
Showing with 14 additions and 1 deletion.
  1. +2 −1  action/Response.php
  2. +12 −0 tests/cases/action/ResponseTest.php
View
3  action/Response.php
@@ -110,8 +110,9 @@ public function type($type = null) {
*/
public function render() {
$code = null;
+ $hasLocation = (isset($this->headers['location']) || isset($this->headers['Location']));
- if (isset($this->headers['location']) && $this->status['code'] === 200) {
+ if ($hasLocation && $this->status['code'] === 200) {
$code = 302;
}
$this->_writeHeader($this->status($code) ?: $this->status(500));
View
12 tests/cases/action/ResponseTest.php
@@ -191,6 +191,18 @@ public function testLocationHeaderStatus() {
$this->assertEqual(array('Location: /foo_bar'), $this->response->headers());
}
+ /**
+ * Tests that, when a location is assigned without a status code being set, that the status code
+ * will be automatically set to 302 when the response is rendered.
+ */
+ public function testBrowserRedirection() {
+ $this->response = new MockResponse(array('location' => '/'));
+ ob_start();
+ $this->response->render();
+ ob_get_clean();
+ $this->assertEqual('HTTP/1.1 302 Found', $this->response->status());
+ }
+
public static function match($url) {
if ($url == array('controller' => 'foo_bar', 'action' => 'index')) {
return '/foo_bar';
Please sign in to comment.
Something went wrong with that request. Please try again.