Skip to content

Commit

Permalink
Add option to specify the timeout (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
VincentBean authored Apr 4, 2023
1 parent 642873a commit f5bda93
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions config/akeneo.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,9 @@
\JustBetter\AkeneoClient\Http\Middleware\HMacMiddleware::class,
],

/* Specify the timeout (in seconds) for the request. */
'timeout' => 30,

/* Specify the connection timeout (in seconds) for the request. */
'connect_timeout' => 10,
];
2 changes: 2 additions & 0 deletions src/Client/Akeneo.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static function fake(): void
'username' => '::username::',
'password' => '::password::',
'webhook_secret' => '::webhook-secret::',
'timeout' => 30,
'connect_timeout' => 10,
]);

Http::fake([
Expand Down
8 changes: 8 additions & 0 deletions src/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ public function sendRequest(RequestInterface $request): ResponseInterface

$contentType = Arr::first(Arr::wrap($contentTypes)) ?? 'application/json';

/** @var int $timeout */
$timeout = config('akeneo.timeout');

/** @var int $connectTimeout */
$connectTimeout = config('akeneo.connect_timeout');

return Http::withHeaders($headers)
->timeout($timeout)
->connectTimeout($connectTimeout)
->withBody($request->getBody()->getContents(), $contentType)
->send($request->getMethod(), $request->getUri())
->toPsrResponse();
Expand Down

0 comments on commit f5bda93

Please sign in to comment.