Skip to content

Commit

Permalink
feat: allow setting custom guzzle options (#4)
Browse files Browse the repository at this point in the history
Co-authored-by: Nicolas Hedger <[email protected]>
  • Loading branch information
palmiak and nhedger authored Nov 20, 2024
1 parent 63571c9 commit aa94508
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 3 additions & 1 deletion config/unicon.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@

'iconify' => [
'url' => 'https://api.iconify.design',
'timeout' => 5,
'request_options' => [
'timeout' => 5,
],
],

];
15 changes: 15 additions & 0 deletions docs/config-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,20 @@ icon: 'gear'

If the request times out, the component won't be rendered.
</ParamField>
<ParamField path="request_options" type="map" default="['timeout' => 5]">
This value is a map of http request options to be passed to the underlying Guzzle client
for all requests to the Iconify API.

For example, you can set the `timeout` option to set a custom timeout.

```php
'request_options' => [
'timeout' => 10,
],
```

See the Guzzle documentation about the [request options](https://docs.guzzlephp.org/en/stable/request-options.html)
for more information.
</ParamField>
</Expandable>
</ParamField>
2 changes: 1 addition & 1 deletion src/IconDownloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function download(string $prefix, string $name): ?string
{
try {
return Http::baseUrl(config('unicon.iconify.url'))
->timeout(config('unicon.iconify.timeout', 5))
->withOptions(config('unicon.iconify.request_options', []))
->get("$prefix/$name.svg")
->throwUnlessStatus(200)
->body();
Expand Down

0 comments on commit aa94508

Please sign in to comment.