Skip to content

Commit

Permalink
only string URL
Browse files Browse the repository at this point in the history
  • Loading branch information
mosaxiv committed Feb 11, 2018
1 parent 0de7964 commit 45bec38
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
15 changes: 6 additions & 9 deletions src/Http/Response.php
Expand Up @@ -22,7 +22,6 @@
use Cake\Http\CorsBuilder;
use Cake\Http\Exception\NotFoundException;
use Cake\Log\Log;
use Cake\Routing\Router;
use DateTime;
use DateTimeZone;
use InvalidArgumentException;
Expand Down Expand Up @@ -1990,25 +1989,23 @@ public function withLength($bytes)
* ### Examples
*
* ```
* $response = $response->withAddedLink('http://example.com', ['rel' => 'prev'])
* ->withAddedLink(['controller' => 'Posts', 'action' => 'view'], ['rel' => 'next']);
* $response = $response->withAddedLink('http://example.com?page=1', ['rel' => 'prev'])
* ->withAddedLink('http://example.com?page=3', ['rel' => 'next']);
* ```
*
* Will generate:
*
* ```
* Link: <http://example.com>; rel="prev"
* Link: </posts/view>; rel="next"
* Link: <http://example.com?page=1>; rel="prev"
* Link: <http://example.com?page=3>; rel="next"
* ```
*
* @param string|array $url link-value
* @param string $url link-value
* @param array $options link-param
* @return static
*/
public function withAddedLink($url, $options = [])
{
$url = '<' . Router::url($url) . '>';

$params = [];
foreach ($options as $key => $option) {
$params[] = $key . '="' . $option . '"';
Expand All @@ -2019,7 +2016,7 @@ public function withAddedLink($url, $options = [])
$param = '; ' . implode('; ', $params);
}

return $this->withAddedHeader('Link', $url . $param);
return $this->withAddedHeader('Link', '<' . $url . '>' . $param);
}

/**
Expand Down
3 changes: 0 additions & 3 deletions tests/TestCase/Http/ResponseTest.php
Expand Up @@ -950,9 +950,6 @@ public function testWithAddedLink()
$this->assertFalse($response->hasHeader('Link'), 'Old instance not modified');
$this->assertEquals('<http://example.com>; rel="prev"', $new->getHeaderLine('Link'));

$new = $response->withAddedLink([], ['rel' => 'prev']);
$this->assertEquals('</>; rel="prev"', $new->getHeaderLine('Link'));

$new = $response->withAddedLink('http://example.com');
$this->assertEquals('<http://example.com>', $new->getHeaderLine('Link'));

Expand Down

0 comments on commit 45bec38

Please sign in to comment.