Skip to content
Permalink
Browse files

Don't append an empty Cookie header

The HttpClient should not append `Cookie:` to the request if there are
no cookies.
  • Loading branch information...
markstory committed Aug 4, 2017
1 parent 4253fe7 commit 1f8763764419c68fa684f6a31341a31bab92815d
Showing with 16 additions and 0 deletions.
  1. +3 −0 src/Http/Cookie/CookieCollection.php
  2. +13 −0 tests/TestCase/Http/Cookie/CookieCollectionTest.php
@@ -226,6 +226,9 @@ public function addToRequest(RequestInterface $request, array $extraCookies = []
foreach ($cookies as $key => $value) {
$cookiePairs[] = sprintf("%s=%s", rawurlencode($key), rawurlencode($value));
}
if (empty($cookiePairs)) {
return $request;
}
return $request->withHeader('Cookie', implode('; ', $cookiePairs));
}
@@ -356,6 +356,19 @@ public function testAddToRequest()
$this->assertSame('blog=b', $request->getHeaderLine('Cookie'));
}
/**
* Test adding no cookies
*
* @return void
*/
public function testAddToRequestNoCookies()
{
$collection = new CookieCollection();
$request = new ClientRequest('http://example.com/api');
$request = $collection->addToRequest($request);
$this->assertFalse($request->hasHeader('Cookie'), 'No header should be set.');
}
/**
* Test adding cookies from the collection to request.
*

0 comments on commit 1f87637

Please sign in to comment.
You can’t perform that action at this time.