Browse Source

only string URL

mosaxiv 8 years ago
parent
commit
45bec3884f
2 changed files with 6 additions and 12 deletions
  1. 6 9
      src/Http/Response.php
  2. 0 3
      tests/TestCase/Http/ResponseTest.php

+ 6 - 9
src/Http/Response.php

@@ -22,7 +22,6 @@ use Cake\Http\Cookie\CookieInterface;
 use Cake\Http\CorsBuilder;
 use Cake\Http\Exception\NotFoundException;
 use Cake\Log\Log;
-use Cake\Routing\Router;
 use DateTime;
 use DateTimeZone;
 use InvalidArgumentException;
@@ -1990,25 +1989,23 @@ class Response implements ResponseInterface
      * ### 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 . '"';
@@ -2019,7 +2016,7 @@ class Response implements ResponseInterface
             $param = '; ' . implode('; ', $params);
         }
 
-        return $this->withAddedHeader('Link', $url . $param);
+        return $this->withAddedHeader('Link', '<' . $url . '>' . $param);
     }
 
     /**

+ 0 - 3
tests/TestCase/Http/ResponseTest.php

@@ -950,9 +950,6 @@ class ResponseTest extends TestCase
         $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'));