Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Middleware.php

function Middleware::cookies

Middleware that adds cookies to requests.

The options array must be set to a CookieJarInterface in order to use cookies. This is typically handled for you by a client.

Return value

callable Returns a function that accepts the next handler.

1 call to Middleware::cookies()
HandlerStack::create in vendor/guzzlehttp/guzzle/src/HandlerStack.php
Creates a default handler stack that can be used by clients.

File

vendor/guzzlehttp/guzzle/src/Middleware.php, line 26

Class

Middleware
Functions used to create and wrap handlers with handler middleware.

Namespace

GuzzleHttp

Code

public static function cookies() : callable {
    return static function (callable $handler) : callable {
        return static function ($request, array $options) use ($handler) {
            if (empty($options['cookies'])) {
                return $handler($request, $options);
            }
            elseif (!$options['cookies'] instanceof CookieJarInterface) {
                throw new \InvalidArgumentException('cookies must be an instance of GuzzleHttp\\Cookie\\CookieJarInterface');
            }
            $cookieJar = $options['cookies'];
            $request = $cookieJar->withCookieHeader($request);
            return $handler($request, $options)->then(static function (ResponseInterface $response) use ($cookieJar, $request) : ResponseInterface {
                $cookieJar->extractCookies($request, $response);
                return $response;
            });
        };
    };
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal