Skip to content

Commit 6c60d43

Browse files
authored
Add retry-http client (#726)
* Add retry-http client * Add comment about double test on getChunk * Refactore retry handling * Reduce default timeout * Improve logging messages * Use symfony/httpexception in tests * Use Symfony RetryableHttpClient * Remove timeout
1 parent 82a9e0b commit 6c60d43

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## NOT RELEASED
44

5+
### Added
6+
7+
- Use Symfony `RetryableHttpClient` when available.
8+
59
### Fixed
610

711
- Allow signing request with non-standard region when using custom endpoint?
@@ -72,7 +76,7 @@
7276

7377
- Support for ECS Credentials Provider
7478
- Support for Cognito Identity Provider client in `AwsClientFactory`
75-
- Support for CloudWatch Logs client in `AwsClientFactory`
79+
- Support for Cloud Watch Log client in `AwsClientFactory`
7680

7781
### Fixed
7882

src/AbstractApi.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Psr\Log\LoggerInterface;
1616
use Psr\Log\NullLogger;
1717
use Symfony\Component\HttpClient\HttpClient;
18+
use Symfony\Component\HttpClient\RetryableHttpClient;
1819
use Symfony\Contracts\HttpClient\HttpClientInterface;
1920

2021
/**
@@ -61,8 +62,14 @@ public function __construct($configuration = [], ?CredentialProvider $credential
6162
throw new InvalidArgument(sprintf('Second argument to "%s::__construct()" must be an array or an instance of "%s"', __CLASS__, Configuration::class));
6263
}
6364

64-
$this->httpClient = $httpClient ?? HttpClient::create();
6565
$this->logger = $logger ?? new NullLogger();
66+
if (!isset($httpClient)) {
67+
$httpClient = HttpClient::create();
68+
if (\class_exists(RetryableHttpClient::class)) {
69+
$httpClient = new RetryableHttpClient($httpClient, null, null, 3, $this->logger);
70+
}
71+
}
72+
$this->httpClient = $httpClient;
6673
$this->configuration = $configuration;
6774
$this->credentialProvider = $credentialProvider ?? new CacheProvider(ChainProvider::createDefaultChain($this->httpClient, $this->logger));
6875
}

src/Stream/ResponseBodyStream.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ public function __toString()
4646
public function getChunks(): iterable
4747
{
4848
if (null !== $this->fallback) {
49-
return $this->fallback->getChunks();
49+
yield from $this->fallback->getChunks();
50+
51+
return;
5052
}
5153
if ($this->partialRead) {
5254
throw new LogicException(\sprintf('You can not call "%s". Another process doesn\'t reading "getChunks" till the end.', __METHOD__));

0 commit comments

Comments
 (0)