Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tioncico committed Dec 11, 2019
1 parent fbc4133 commit d3ca414
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
7 changes: 4 additions & 3 deletions src/AliYun/Http/RequestHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace EasySwoole\Oss\AliYun\Http;

use EasySwoole\Oss\AliYun\Config;
use EasySwoole\Oss\AliYun\OssClient;
use EasySwoole\Oss\AliYun\OssConst;

/**
Expand All @@ -33,7 +34,7 @@ public function __construct(Config $config)
$this->config = $config;
}

public function generateHeaders($options, $hostname)
public function generateHeaders($options, $hostname,OssClient $ossClient)
{
$headers = $this->headers;

Expand All @@ -52,8 +53,8 @@ public function generateHeaders($options, $hostname)
}

//添加stsSecurityToken
if ((!is_null($this->config->getSecurityToken())) && (!$this->config->isEnableStsInUrl())) {
$headers[OssConst::OSS_SECURITY_TOKEN] = $this->config->getSecurityToken();
if ((!is_null($ossClient->getSecurityToken())) && (!$ossClient->isEnableStsInUrl())) {
$headers[OssConst::OSS_SECURITY_TOKEN] = $ossClient->getSecurityToken();
}
//合并HTTP headers
if (isset($options[OssConst::OSS_HEADERS])) {
Expand Down
38 changes: 36 additions & 2 deletions src/AliYun/OssClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -1989,7 +1989,7 @@ public function auth(array $options)
$headers = new RequestHeaders($config);
// 获得当次请求使用的hostname,如果是公共域名或者专有域名,bucket拼在前面构成三级域名
$hostname = $this->generateHostname($options[OssConst::OSS_BUCKET]);
$headers = $headers->generateHeaders($options, $hostname);
$headers = $headers->generateHeaders($options, $hostname,$this);
$this->setHttpClientHeaders($httpClient, $headers);
//签名字符串
$stringToSign = $signature->getStringToSign($signableQueryString, $options, $headers, $this->hostType);
Expand Down Expand Up @@ -2099,6 +2099,39 @@ public function setSignStsInUrl($enable)
$this->enableStsInUrl = $enable;
}

/**
* @return bool
*/
public function isEnableStsInUrl(): bool
{
return $this->enableStsInUrl;
}

/**
* @param bool $enableStsInUrl
*/
public function setEnableStsInUrl(bool $enableStsInUrl): void
{
$this->enableStsInUrl = $enableStsInUrl;
}

/**
* @return null
*/
public function getSecurityToken()
{
return $this->securityToken;
}

/**
* @param null $securityToken
*/
public function setSecurityToken($securityToken): void
{
$this->securityToken = $securityToken;
}


/**
* @return boolean
*/
Expand Down Expand Up @@ -2573,6 +2606,7 @@ protected function downFile(Response $response,$options){
}
$file->write($response->getBody());
}

}


}
6 changes: 3 additions & 3 deletions tests/AliYun/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* Date: 2019/11/20 0020
* Time: 15:28
*/
include "./vendor/autoload.php";
include "./phpunit.php";
include "../../vendor/autoload.php";
include "../../phpunit2.php";

go(function (){

Expand All @@ -16,6 +16,6 @@
'endpoint' => END_POINT,
]);
$client = new \EasySwoole\Oss\AliYun\OssClient($config);
$data = $client->putObject('tioncicoxyz','test',__FILE__);
$data = $client->putObject('tioncicoxyz','test11',__FILE__);
var_dump($data);
});

0 comments on commit d3ca414

Please sign in to comment.