public function HttpClientMiddleware::__invoke in Devel 8.2
Same name and namespace in other branches
- 8.3 webprofiler/src/Http/HttpClientMiddleware.php \Drupal\webprofiler\Http\HttpClientMiddleware::__invoke()
- 8 webprofiler/src/Http/HttpClientMiddleware.php \Drupal\webprofiler\Http\HttpClientMiddleware::__invoke()
- 4.x webprofiler/src/Http/HttpClientMiddleware.php \Drupal\webprofiler\Http\HttpClientMiddleware::__invoke()
File
- webprofiler/
src/ Http/ HttpClientMiddleware.php, line 35
Class
- HttpClientMiddleware
- Class HttpClientMiddleware
Namespace
Drupal\webprofiler\HttpCode
public function __invoke() {
return function ($handler) {
return function (RequestInterface $request, array $options) use ($handler) {
// If on_stats callback is already set then save it
// and call it after ours.
if (isset($options['on_stats'])) {
$next = $options['on_stats'];
}
else {
$next = function (TransferStats $stats) {
};
}
$options['on_stats'] = function (TransferStats $stats) use ($request, $next) {
$request->stats = $stats;
$next($stats);
};
return $handler($request, $options)
->then(function ($response) use ($request) {
$this->completedRequests[] = [
'request' => $request,
'response' => $response,
];
return $response;
}, function ($reason) use ($request) {
$response = $reason instanceof RequestException ? $reason
->getResponse() : null;
$this->failedRequests[] = [
'request' => $request,
'response' => $response,
'message' => $reason
->getMessage(),
];
return \GuzzleHttp\Promise\rejection_for($reason);
});
};
};
}