Merge pull request #1428 from markstory/2.4-location

2.4 location
This commit is contained in:
Mark Story 2013-07-17 18:19:13 -07:00
commit 204fb4b864
2 changed files with 28 additions and 0 deletions

View file

@ -584,6 +584,22 @@ class CakeResponse {
return $this->_headers;
}
/**
* Acccessor for the location header.
*
* Get/Set the Location header value.
* @param null|string $url Either null to get the current location, or a string to set one.
* @return string|null When setting the location null will be returned. When reading the location
* a string of the current location header value (if any) will be returned.
*/
public function location($url = null) {
if ($url === null) {
$headers = $this->header();
return isset($headers['Location']) ? $headers['Location'] : null;
}
$this->header('Location', $url);
}
/**
* Buffers the response message to be sent
* if $content is null the current buffer is returned

View file

@ -1481,4 +1481,16 @@ class CakeResponseTest extends CakeTestCase {
$result = $response->send();
}
/**
* Test the location method.
*
* @return void
*/
public function testLocation() {
$response = new CakeResponse();
$this->assertNull($response->location(), 'No header should be set.');
$this->assertNull($response->location('http://example.org'), 'Setting a location should return null');
$this->assertEquals('http://example.org', $response->location(), 'Reading a location should return the value.');
}
}