diff --git a/webprofiler/src/Http/HttpClientMiddleware.php b/webprofiler/src/Http/HttpClientMiddleware.php index b64a2a6cc5cf79f118aaea6df554355f0edfc320..c37c0ca6f9c4bc20c8461e77765916f946240340 100644 --- a/webprofiler/src/Http/HttpClientMiddleware.php +++ b/webprofiler/src/Http/HttpClientMiddleware.php @@ -36,8 +36,18 @@ class HttpClientMiddleware { return function ($handler) { return function (RequestInterface $request, array $options) use ($handler) { - $options['on_stats'] = function (TransferStats $stats) use ($request) { + // 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(