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
27 changes: 19 additions & 8 deletions src/Qcloud/Cos/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function commandToRequestTransformer(CommandInterface $command)
$request = $seri($command);
$request = $transformer->bucketStyleTransformer($command, $request);
$request = $transformer->uploadBodyTransformer($command, $request);
$request = $transformer->metadataTransformer($command, $request);
$request = $transformer->md5Transformer($command, $request);
$request = $transformer->specialParamTransformer($command, $request);
return $request;
Expand All @@ -103,16 +104,26 @@ public function responseToResultTransformer(ResponseInterface $response, Request
}
}
$deseri = new Deserializer($this->desc, true);
$response = $deseri($response, $request, $command);
if ($command['Key'] != null && $response['Key'] == null) {
$response['Key'] = $command['Key'];
$rsp = $deseri($response, $request, $command);

$headers = $response->getHeaders();
$metadata = array();
foreach ($headers as $key => $value) {
if (strpos($key, "x-cos-meta-") === 0) {
$metadata[substr($key, 11)] = $value[0];
}
}
if ($command['Bucket'] != null && $response['Bucket'] == null) {
$response['Bucket'] = $command['Bucket'];
if (!empty($metadata)) {
$rsp['Metadata'] = $metadata;
}
$response['Location'] = $request->getHeader("Host")[0] . $request->getUri()->getPath();

return $response;
if ($command['Key'] != null && $rsp['Key'] == null) {
$rsp['Key'] = $command['Key'];
}
if ($command['Bucket'] != null && $rsp['Bucket'] == null) {
$rsp['Bucket'] = $command['Bucket'];
}
$rsp['Location'] = $request->getHeader("Host")[0] . $request->getUri()->getPath();
return $rsp;
}
public function __destruct() {
}
Expand Down
14 changes: 13 additions & 1 deletion src/Qcloud/Cos/CosTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ public function md5Transformer(CommandInterface $command, $request) {
return $request;
}

// add meta
public function metadataTransformer(CommandInterface $command, $request) {
$operation = $this->operation;
if (isset($command['Metadata'])) {
$meta = $command['Metadata'];
foreach ($meta as $key => $value) {
$request = $request->withHeader('x-cos-meta-' . $key, $value);
}
}
return $request;
}

// count md5
private function addMd5($request) {
$body = $request->getBody();
Expand All @@ -128,7 +140,7 @@ private function addMd5($request) {
return $request;
}

// count md5
// inventoryId
public function specialParamTransformer(CommandInterface $command, $request) {
$action = $command->getName();
if ($action == 'PutBucketInventory') {
Expand Down
40 changes: 0 additions & 40 deletions src/Qcloud/Cos/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,6 @@ public static function getService() {
'Qcloud\\Cos\\Client::explodeKey'
)
),
'Metadata' => array(
'type' => 'object',
'location' => 'header',
'sentAs' => 'x-cos-meta-',
'additionalProperties' => array(
'type' => 'string',
),
),
'ServerSideEncryption' => array(
'type' => 'string',
'location' => 'header',
Expand Down Expand Up @@ -381,14 +373,6 @@ public static function getService() {
'filters' => array(
'Qcloud\\Cos\\Client::explodeKey')
),
'Metadata' => array(
'type' => 'object',
'location' => 'header',
'sentAs' => 'x-cos-meta-',
'additionalProperties' => array(
'type' => 'string',
),
),
'MetadataDirective' => array(
'type' => 'string',
'location' => 'header',
Expand Down Expand Up @@ -1160,14 +1144,6 @@ public static function getService() {
'Qcloud\\Cos\\Client::explodeKey'
)
),
'Metadata' => array(
'type' => 'object',
'location' => 'header',
'sentAs' => 'x-cos-meta-',
'additionalProperties' => array(
'type' => 'string'
)
),
'ServerSideEncryption' => array(
'type' => 'string',
'location' => 'header',
Expand Down Expand Up @@ -3081,14 +3057,6 @@ public static function getService() {
'location' => 'header',
'sentAs' => 'x-cos-server-side-encryption',
),
'Metadata' => array(
'type' => 'object',
'location' => 'header',
'sentAs' => 'x-cos-meta-',
'additionalProperties' => array(
'type' => 'string',
),
),
'SSECustomerAlgorithm' => array(
'type' => 'string',
'location' => 'header',
Expand Down Expand Up @@ -4647,14 +4615,6 @@ public static function getService() {
'location' => 'header',
'sentAs' => 'x-cos-server-side-encryption',
),
'Metadata' => array(
'type' => 'object',
'location' => 'header',
'sentAs' => 'x-cos-meta-',
'additionalProperties' => array(
'type' => 'string',
),
),
'SSECustomerAlgorithm' => array(
'type' => 'string',
'location' => 'header',
Expand Down
37 changes: 34 additions & 3 deletions src/Qcloud/Cos/Tests/Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1006,13 +1006,44 @@ public function testPutObjectExisted() {
*/
public function testPutObjectMeta() {
try {
$key = '你好.txt';
$meta = array(
'test' => str_repeat('a', 1 * 1024),
'test-meta' => 'qwe-23ds-ad-xcz.asd.*qweqw'
);
$this->cosClient->putObject(array(
'Bucket' => $this->bucket,
'Key' => '你好.txt',
'Body' => '1234124',
'Metadata' => array(
'lew' => str_repeat('a', 1 * 1024),
)));
'Metadata' => $meta

));
$rt = $this->cosClient->headObject(['Bucket'=>$this->bucket, 'Key'=>$key]);
$this->assertEquals($rt['Metadata'], $meta);
} catch (ServiceResponseException $e) {
print $e;
$this->assertFalse(TRUE);
}
}

/*
* upload large object,请求头部携带自定义头部x-cos-meta-
* 200
*/
public function testUploadLargeObjectMeta() {
try {
$key = '你好.txt';
$meta = array(
'test' => str_repeat('a', 1 * 1024),
'test-meta' => 'qwe-23ds-ad-xcz.asd.*qweqw'
);
$body = $this->generateRandomString(2*1024*1024+1023);
$this->cosClient->upload($bucket=$this->bucket,
$key=$key,
$body=$body,
$options=['PartSize'=>1024 * 1024 + 1, 'Metadata'=>$meta]);
$rt = $this->cosClient->headObject(['Bucket'=>$this->bucket, 'Key'=>$key]);
$this->assertEquals($rt['Metadata'], $meta);
} catch (ServiceResponseException $e) {
print $e;
$this->assertFalse(TRUE);
Expand Down