Skip to content

Commit

Permalink
Added HTTP client override configuration
Browse files Browse the repository at this point in the history
Ability to set a custom timeout on the HTTP client configuration. By default, this uses Guzzle.
  • Loading branch information
j-webb committed Jul 12, 2023
1 parent 2378ef2 commit b99949c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
21 changes: 21 additions & 0 deletions config/unleash.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
|
| Unleash cache settings. This will cache any API object responses for the
| duration of the TTL.
| The cache is used to prevent stressing the feature flag endpoint.
|
*/

Expand All @@ -89,6 +90,26 @@
'handler' => JWebb\Unleash\Cache\CacheHandler::class
],


/*
|--------------------------------------------------------------------------
| HTTP Client Override
|--------------------------------------------------------------------------
|
| HTTP Client configuration settings.
| Setting the timeout settings manually will break the connection to an
| unstable endpoint and fail early.
|
*/

'http_client_override' => [
'enabled' => env('UNLEASH_HTTP_CLIENT_OVERRIDE', false),
'config' => [
'timeout' => env('UNLEASH_HTTP_TIMEOUT', 5),
'connect_timeout' => env('UNLEASH_HTTP_CONNECT_TIMEOUT', 5),
]
],

/*
|--------------------------------------------------------------------------
| API Key
Expand Down
7 changes: 6 additions & 1 deletion src/Providers/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace JWebb\Unleash\Providers;

use GuzzleHttp\Client;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
use JWebb\Unleash\Interfaces\UnleashCacheHandlerInterface;
Expand Down Expand Up @@ -31,7 +32,11 @@ public function register(): void
->withStrategies(...(new $strategyProvider())->getStrategies())
->withAutomaticRegistrationEnabled(!! config('unleash.automatic_registration'))
->withMetricsEnabled(!! config('unleash.metrics'));


if (!! config('unleash.http_client_override.enabled')) {
$builder = $builder->withHttpClient(new Client(config('unleash.http_client_override.config')));
}

if (!! config('unleash.cache.enabled')) {
/** @var UnleashCacheHandlerInterface $cacheHandler */
$cacheHandler = config('unleash.cache.handler');
Expand Down
9 changes: 4 additions & 5 deletions src/Unleash.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@
use Unleash\Client\DTO\Variant;
use Unleash\Client\Repository\UnleashRepository;
use Unleash\Client\Unleash as UnleashClient;
use Unleash\Client\Unleash as UnleashImplemtation;

class Unleash implements UnleashImplemtation
class Unleash implements UnleashClient
{
/**
* @var UnleashImplemtation
* @var UnleashClient
*/
public UnleashClient $client;

/**
* Unleash constructor.
* @param UnleashImplemtation $client
* @param UnleashClient $client
*/
public function __construct(UnleashClient $client)
{
Expand Down Expand Up @@ -107,4 +106,4 @@ protected function getRepository(): UnleashRepository

return $reflectionProperty->getValue($this->client);
}
}
}

0 comments on commit b99949c

Please sign in to comment.