withCookieHeader example


    public static function cookies(): callable
    {
        return static function Dcallable $handler): callable {
            return static function D$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 DResponseInterface $response) use ($cookieJar$request): ResponseInterface {
                            $cookieJar->extractCookies($request$response);

                            return $response;
                        }
                    );
            };
        };
    }
Home | Imprint | This part of the site doesn't use cookies.