Skip to content
Open
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
18 changes: 18 additions & 0 deletions src/Request/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ abstract class Request implements ArrayAccess
*/
public $client;

/**
* @var \AlibabaCloud\Client\Clients\Client
*/
public $httpClient;

/**
* @var Uri
*/
Expand Down Expand Up @@ -286,6 +291,19 @@ public function client($clientName)
return $this;
}


/**
*
*
* @param \AlibabaCloud\Client\Clients\Client $client
* @return $this
*/
public function withHttpClient(\AlibabaCloud\Client\Clients\Client $client)
{
$this->httpClient = $client;
return $this;
}

/**
* @return bool
* @throws ClientException
Expand Down
4 changes: 4 additions & 0 deletions src/Request/Traits/ClientTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function credential()
*/
public function httpClient()
{
if ($this->httpClient){
return $this->httpClient;
}

if (!AlibabaCloud::all()) {
if (CredentialsProvider::hasCustomChain()) {
CredentialsProvider::customProvider($this->client);
Expand Down
11 changes: 11 additions & 0 deletions tests/Unit/Request/Traits/ClientTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ public function testHttpClient()
$request->httpClient();
}

/**
* @throws ClientException
*/
public function testCustomHttpClient()
{
$httpClient = AlibabaCloud::accessKeyClient('key', 'secret')
->regionId('cn-hangzhou');
$request = AlibabaCloud::rpc()->withHttpClient($httpClient);
self::assertEquals($httpClient,$request->httpClient);
}

/**
* @throws ClientException
*/
Expand Down