You are here

public function CookieJar::withCookieHeader in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php \GuzzleHttp\Cookie\CookieJar::withCookieHeader()

Create a request with added cookie headers.

If no matching cookies are found in the cookie jar, then no Cookie header is added to the request and the same request is returned.

Parameters

RequestInterface $request Request object to modify.:

Return value

RequestInterface returns the modified request.

Overrides CookieJarInterface::withCookieHeader

File

vendor/guzzlehttp/guzzle/src/Cookie/CookieJar.php, line 236

Class

CookieJar
Cookie jar that stores cookies an an array

Namespace

GuzzleHttp\Cookie

Code

public function withCookieHeader(RequestInterface $request) {
  $values = [];
  $uri = $request
    ->getUri();
  $scheme = $uri
    ->getScheme();
  $host = $uri
    ->getHost();
  $path = $uri
    ->getPath() ?: '/';
  foreach ($this->cookies as $cookie) {
    if ($cookie
      ->matchesPath($path) && $cookie
      ->matchesDomain($host) && !$cookie
      ->isExpired() && (!$cookie
      ->getSecure() || $scheme == 'https')) {
      $values[] = $cookie
        ->getName() . '=' . self::getCookieValue($cookie
        ->getValue());
    }
  }
  return $values ? $request
    ->withHeader('Cookie', implode('; ', $values)) : $request;
}