Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added HTTP client override configuration #27

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}
}