Skip to content

Commit 29a42ce

Browse files
Add RequestIdSettingHttpClient
1 parent 24d347a commit 29a42ce

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace SBSEDV\Bundle\RequestIdBundle\HttpClient;
4+
5+
use SBSEDV\Bundle\RequestIdBundle\Provider\RequestIdProviderInterface;
6+
use Symfony\Component\HttpClient\DecoratorTrait;
7+
use Symfony\Contracts\HttpClient\HttpClientInterface;
8+
use Symfony\Contracts\HttpClient\ResponseInterface;
9+
10+
class RequestIdSettingHttpClient implements HttpClientInterface
11+
{
12+
use DecoratorTrait;
13+
14+
public function __construct(
15+
private HttpClientInterface $client,
16+
private RequestIdProviderInterface $requestIdProvider,
17+
private string $headerName = 'x-request-id'
18+
) {
19+
}
20+
21+
/**
22+
* {@inheritdoc}
23+
*/
24+
public function request(string $method, string $url, array $options = []): ResponseInterface
25+
{
26+
@$options['headers'][$this->headerName] = $this->requestIdProvider->getCurrentRequestId();
27+
28+
return $this->request($method, $url, $options);
29+
}
30+
}

0 commit comments

Comments
 (0)