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

Allow replacing the guzzle handler #956

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Firebase/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use GuzzleHttp\Client;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\Psr7\HttpFactory;
use GuzzleHttp\Psr7\Utils as GuzzleUtils;
use Kreait\Firebase\AppCheck\AppCheckTokenGenerator;
Expand All @@ -41,6 +42,7 @@
use Kreait\Firebase\Messaging\RequestFactory;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Clock\ClockInterface;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\UriInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LogLevel;
Expand Down Expand Up @@ -540,7 +542,7 @@ public function createApiClient(?array $config = null, ?array $middlewares = nul

$config = [...$this->httpClientOptions->guzzleConfig(), ...$config];

$handler = HandlerStack::create();
$handler = HandlerStack::create($this->httpClientOptions->guzzleHandler());

if ($this->httpLogMiddleware) {
$handler->push($this->httpLogMiddleware, 'http_logs');
Expand Down
24 changes: 24 additions & 0 deletions src/Firebase/Http/HttpClientOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,18 @@

namespace Kreait\Firebase\Http;

use GuzzleHttp\Promise\PromiseInterface;
use GuzzleHttp\RequestOptions;
use Kreait\Firebase\Exception\InvalidArgumentException;
use Psr\Http\Message\RequestInterface;

use function is_callable;

final class HttpClientOptions
{
/** @var callable(RequestInterface, array): PromiseInterface|null */
private $guzzleHandler = null;

/**
* @param array<non-empty-string, mixed> $guzzleConfig
* @param list<array{middleware: callable, name: string}> $guzzleMiddlewares
Expand Down Expand Up @@ -190,4 +195,23 @@ public function withGuzzleMiddlewares(array $middlewares): self

return new self($this->guzzleConfig, $newMiddlewares);
}

/**
* The guzzle Handler to be used in Guzzles HandlerStack.
*
* @return callable(RequestInterface, array): PromiseInterface|null
*/
public function guzzleHandler(): callable|null
{
return $this->guzzleHandler;
}

/**
* @param callable(RequestInterface, array): PromiseInterface $value the guzzle Handler to be used in Guzzles HandlerStack
*/
public function withGuzzleHandler(callable $handler): self
{
$this->guzzleHandler = $handler;
return $this;
}
}