diff --git a/src/Blackfire/Bridge/Symfony/BlackfiredHttpClient.php b/src/Blackfire/Bridge/Symfony/BlackfiredHttpClient.php index c67d199..f0554f3 100644 --- a/src/Blackfire/Bridge/Symfony/BlackfiredHttpClient.php +++ b/src/Blackfire/Bridge/Symfony/BlackfiredHttpClient.php @@ -13,7 +13,6 @@ use Blackfire\Client as BlackfireClient; use Blackfire\Profile\Configuration as ProfileConfiguration; -use Blackfire\Profile\Request; use Psr\Log\LoggerInterface; use Symfony\Component\HttpClient\HttpClientTrait; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -42,7 +41,11 @@ public function request(string $method, string $url, array $options = array()): // this normalizes HTTP headers and allows direct access to $options['headers']['x-blackfire-query'] // without checking the header name case sensitivity [, $options] = self::prepareRequest($method, $url, $options, static::OPTIONS_DEFAULTS); - $profileRequest = null; + if (!isset($options['extra'])) { + $options['extra'] = array(); + } + + $profileRequest = $options['extra']['profile_request'] ?? null; if ($this->shouldAutoEnable() && !isset($options['extra']['blackfire'])) { $options['extra']['blackfire'] = new ProfileConfiguration(); @@ -64,20 +67,22 @@ public function request(string $method, string $url, array $options = array()): throw new \InvalidArgumentException('blackfire must be true or an instance of \Blackfire\Profile\Configuration.'); } - $profileRequest = $this->blackfire->createRequest($options['extra']['blackfire']); + if (!$profileRequest) { + $options['extra']['profile_request'] = $this->blackfire->createRequest($options['extra']['blackfire']); + } if (isset($probe)) { $probe->enable(); } - $options['headers']['X-Blackfire-Query'] = $profileRequest->getToken(); - $options['headers']['X-Blackfire-Profile-Url'] = $profileRequest->getProfileUrl(); - $options['headers']['X-Blackfire-Profile-Uuid'] = $profileRequest->getUuid(); + $options['headers']['X-Blackfire-Query'] = $options['extra']['profile_request']->getToken(); + $options['headers']['X-Blackfire-Profile-Url'] = $options['extra']['profile_request']->getProfileUrl(); + $options['headers']['X-Blackfire-Profile-Uuid'] = $options['extra']['profile_request']->getUuid(); } $response = $this->client->request($method, $url, $options); - return $this->processResponse($method, $url, $options, $response, $profileRequest); + return $this->processResponse($method, $url, $options, $response); } public function stream($responses, float $timeout = null): ResponseStreamInterface @@ -85,9 +90,10 @@ public function stream($responses, float $timeout = null): ResponseStreamInterfa return $this->client->stream($responses, $timeout); } - private function processResponse($method, $url, array $options, ResponseInterface $response, Request $request = null) + private function processResponse($method, $url, array $options, ResponseInterface $response) { $headers = $response->getHeaders(false); + $request = $options['extra']['profile_request'] ?? null; if (!isset($headers['x-blackfire-response'])) { if (null !== $this->logger) { @@ -117,6 +123,8 @@ private function processResponse($method, $url, array $options, ResponseInterfac return new BlackfiredHttpResponse($response, $request); } + $options['extra']['profile_request'] = $request; + return $this->request($method, $url, $options); }