Skip to content
Merged
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
23 changes: 15 additions & 8 deletions src/Qcloud/Cos/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct($cosConfig) {
$this->cosConfig['endpoint'] = isset($cosConfig['endpoint']) ? $cosConfig['endpoint'] : 'myqcloud.com';
$this->cosConfig['domain'] = isset($cosConfig['domain']) ? $cosConfig['domain'] : null;
$this->cosConfig['proxy'] = isset($cosConfig['proxy']) ? $cosConfig['proxy'] : null;
$this->cosConfig['retry'] = isset($cosConfig['retry']) ? $cosConfig['retry'] : 1;
$this->cosConfig['userAgent'] = isset($cosConfig['userAgent']) ? $cosConfig['userAgent'] : 'cos-php-sdk-v5.'. Client::VERSION;
$this->cosConfig['pathStyle'] = isset($cosConfig['pathStyle']) ? $cosConfig['pathStyle'] : false;

Expand Down Expand Up @@ -113,14 +114,20 @@ public function __destruct() {
}

public function __call($method, array $args) {
try {
return parent::__call(ucfirst($method), $args);
} catch (CommandException $e) {
$previous = $e->getPrevious();
if ($previous !== null) {
throw $previous;
} else {
throw $e;
for ($i = 1; $i <= $this->cosConfig['retry']; $i++) {
try {
return parent::__call(ucfirst($method), $args);
} catch (CommandException $e) {
if ($i != $this->cosConfig['retry']) {
sleep(1 << ($i-1));
continue;
}
$previous = $e->getPrevious();
if ($previous !== null) {
throw $previous;
} else {
throw $e;
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Qcloud/Cos/CommandToRequestTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public function metadataTransformer(CommandInterface $command, $request) {
$request = $request->withHeader('x-cos-meta-' . $key, $value);
}
}
$request = headersMap($command, $request);
return $request;
}

Expand Down
13 changes: 13 additions & 0 deletions src/Qcloud/Cos/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,16 @@ function endWith($haystack, $needle) {
}
return (substr($haystack, -$length) === $needle);
}

function headersMap($command, $request) {
$headermap = array(
'TransferEncoding'=>'Transfer-Encoding',
'ChannelId'=>'x-cos-channel-id'
);
foreach ($headermap as $key => $value) {
if (isset($command[$key])) {
$request = $request->withHeader($value, $command[$key]);
}
}
return $request;
}
1 change: 0 additions & 1 deletion src/Qcloud/Cos/Tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public function testValidRegionBucket()
$regionlist = array('cn-east','ap-shanghai',
'cn-south','ap-guangzhou',
'cn-north','ap-beijing-1',
'cn-south-2','ap-guangzhou-2',
'cn-southwest','ap-chengdu',
'sg','ap-singapore',
'tj','ap-beijing-1',
Expand Down