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
GuzzleHttpCode
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;
});
};
};
}