public static function Middleware::cookies in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/guzzlehttp/guzzle/src/Middleware.php \GuzzleHttp\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 27
Class
- Middleware
- Functions used to create and wrap handlers with handler middleware.
Namespace
GuzzleHttpCode
public static function cookies() {
return function (callable $handler) {
return 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(function ($response) use ($cookieJar, $request) {
$cookieJar
->extractCookies($request, $response);
return $response;
});
};
};
}