-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(http): add option to configure http client, better usage with in…
…terceptor
- Loading branch information
Showing
6 changed files
with
56 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Asynit\HttpClient; | ||
|
||
use Amp\Cancellation; | ||
use Amp\Http\Client\ApplicationInterceptor; | ||
use Amp\Http\Client\DelegateHttpClient; | ||
use Amp\Http\Client\Request; | ||
use Amp\Http\Client\Response; | ||
use Asynit\Attribute\HttpClientConfiguration; | ||
|
||
final readonly class ConfigurationInterceptor implements ApplicationInterceptor | ||
{ | ||
public function __construct(private HttpClientConfiguration $configuration) | ||
{ | ||
} | ||
|
||
public function request(Request $request, Cancellation $cancellation, DelegateHttpClient $httpClient): Response | ||
{ | ||
$request->setInactivityTimeout($this->configuration->timeout); | ||
$request->setTcpConnectTimeout($this->configuration->timeout); | ||
$request->setTlsHandshakeTimeout($this->configuration->timeout); | ||
$request->setTransferTimeout($this->configuration->timeout); | ||
|
||
return $httpClient->request($request, $cancellation); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters