You are here

public function CookieJar::withCookieHeader in Auth0 Single Sign On 8.2

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 275

Class

CookieJar
Cookie jar that stores cookies as 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() . '=' . $cookie
        ->getValue();
    }
  }
  return $values ? $request
    ->withHeader('Cookie', implode('; ', $values)) : $request;
}