Skip to content

Commit 246d40c

Browse files
authored
Revert "Revert "Do not override HttpClient DI"" (#1240)
This reverts commit b3d80e39707f220fade8c297af3fc500ae5d7ee9.
1 parent f699dfc commit 246d40c

File tree

3 files changed

+43
-9
lines changed

3 files changed

+43
-9
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
- Support for TimestreamQuery
1010
- Support for TimestreamWrite
1111
- AWS enhancement: Documentation updates.
12+
- Reverted the automated decoration of the injected HttpClient
13+
- Added an AwsHttpClientFactory to help people creating retryable clients
1214

1315
### Changed
1416

src/AbstractApi.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ public function __construct($configuration = [], ?CredentialProvider $credential
7474
$this->awsErrorFactory = $this->getAwsErrorFactory();
7575
if (!isset($httpClient)) {
7676
$httpClient = HttpClient::create();
77-
}
78-
if (class_exists(RetryableHttpClient::class) && !$httpClient instanceof RetryableHttpClient) {
79-
/** @psalm-suppress MissingDependency */
80-
$httpClient = new RetryableHttpClient(
81-
$httpClient,
82-
new AwsRetryStrategy(AwsRetryStrategy::DEFAULT_RETRY_STATUS_CODES, 1000, 2.0, 0, 0.1, $this->awsErrorFactory),
83-
3,
84-
$this->logger
85-
);
77+
if (class_exists(RetryableHttpClient::class)) {
78+
/** @psalm-suppress MissingDependency */
79+
$httpClient = new RetryableHttpClient(
80+
$httpClient,
81+
new AwsRetryStrategy(AwsRetryStrategy::DEFAULT_RETRY_STATUS_CODES, 1000, 2.0, 0, 0.1, $this->awsErrorFactory),
82+
3,
83+
$this->logger
84+
);
85+
}
8686
}
8787
$this->httpClient = $httpClient;
8888
$this->configuration = $configuration;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace AsyncAws\Core\HttpClient;
4+
5+
use Psr\Log\LoggerInterface;
6+
use Symfony\Component\HttpClient\HttpClient;
7+
use Symfony\Component\HttpClient\RetryableHttpClient;
8+
use Symfony\Contracts\HttpClient\HttpClientInterface;
9+
10+
/**
11+
* @author Jérémy Derussé <[email protected]>
12+
*/
13+
class AwsHttpClientFactory
14+
{
15+
public static function createRetryableClient(HttpClientInterface $httpClient = null, LoggerInterface $logger = null): HttpClientInterface
16+
{
17+
if (null === $httpClient) {
18+
$httpClient = HttpClient::create();
19+
}
20+
if (class_exists(RetryableHttpClient::class)) {
21+
/** @psalm-suppress MissingDependency */
22+
$httpClient = new RetryableHttpClient(
23+
$httpClient,
24+
new AwsRetryStrategy(),
25+
3,
26+
$logger
27+
);
28+
}
29+
30+
return $httpClient;
31+
}
32+
}

0 commit comments

Comments
 (0)