Skip to content

Commit

Permalink
Allow customization of some guzzle fields
Browse files Browse the repository at this point in the history
- User agent
- Accept
- Cookies
  • Loading branch information
rpungello committed Mar 26, 2024
1 parent f1cd7e1 commit b8c77f1
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/SdkClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class SdkClient
{
protected ?GuzzleClient $guzzle;

public function __construct(protected string $baseUri, protected ?HandlerStack $handler = null)
public function __construct(protected string $baseUri, protected ?HandlerStack $handler = null, protected ?string $userAgent = null, protected ?string $accept = 'application/json', protected bool $cookies = true)
{
$this->guzzle = static::getGuzzleClient();
}
Expand All @@ -40,16 +40,22 @@ protected function getGuzzleClientConfig(): array
{
$config = [
'base_uri' => $this->baseUri,
'cookies' => true,
'headers' => [
'accept' => 'application/json',
],
'cookies' => $this->cookies,
'headers' => [],
];

if (! is_null($this->handler)) {
$config['handler'] = $this->handler;
}

if (! empty($this->userAgent)) {
$config['headers']['user-agent'] = $this->userAgent;
}

if (! empty($this->accept)) {
$config['headers']['accept'] = $this->accept;
}

return $config;
}

Expand Down

0 comments on commit b8c77f1

Please sign in to comment.