Skip to content

Commit 31ac41b

Browse files
committed
add strictObjectName option.
1 parent 58265ff commit 31ac41b

File tree

2 files changed

+36
-15
lines changed

2 files changed

+36
-15
lines changed

src/OSS/OssClient.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,21 @@ private function __initNewClient($config = array())
178178
$this->region = isset($config['region']) ? $config['region'] : '';
179179
$this->cloudBoxId = isset($config['cloudBoxId']) ? $config['cloudBoxId'] : '';
180180

181-
$signatureVersion = isset($config['signatureVersion']) ? $config['signatureVersion'] : self::OSS_SIGNATURE_VERSION_V1;
181+
// $enableStrictObjName
182+
$this->enableStrictObjName = true;
183+
if (isset($config['strictObjectName'])) {
184+
if ($config['strictObjectName'] === false) {
185+
$this->enableStrictObjName = false;
186+
}
187+
}
188+
189+
// sign version
190+
$signatureVersion = self::OSS_SIGNATURE_VERSION_V1;
191+
if (isset($config['signatureVersion']) && $config['signatureVersion'] === self::OSS_SIGNATURE_VERSION_V4) {
192+
$signatureVersion = self::OSS_SIGNATURE_VERSION_V4;
193+
}
182194
if ($signatureVersion === self::OSS_SIGNATURE_VERSION_V4) {
195+
$this->enableStrictObjName = false;
183196
$this->signer = new SignerV4();
184197
} else {
185198
$this->signer = new SignerV1();
@@ -3267,17 +3280,6 @@ public function getMaxRetries()
32673280
*/
32683281
public function setSignStsInUrl($enable)
32693282
{
3270-
$this->enableStsInUrl = $enable;
3271-
}
3272-
3273-
/**
3274-
* Enable/disable strict object name.
3275-
*
3276-
* @param boolean $enable
3277-
*/
3278-
public function setStrictObjectName($enable)
3279-
{
3280-
$this->enableStrictObjName = $enable;
32813283
}
32823284

32833285
/**
@@ -3743,7 +3745,7 @@ public function setConnectTimeout($connectTimeout)
37433745
*/
37443746
private $provider;
37453747
private $hostname;
3746-
private $enableStrictObjName = true;
3748+
private $enableStrictObjName;
37473749
private $timeout = 0;
37483750
private $connectTimeout = 0;
37493751
private $cloudBoxId = null;

tests/OSS/Tests/OssClientSignatureTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,37 @@ public function testSignedUrlWithException()
107107
}
108108
}
109109

110+
// Set StrictObjectName false
110111
$object = "?a.file";
111112
$timeout = 3600;
112113
$options = array('Content-Type' => 'txt');
114+
$config = array(
115+
'strictObjectName' => false
116+
);
117+
$ossClient = Common::getOssClient($config);
113118
try {
114-
$this->ossClient->setStrictObjectName(false);
115-
$signedUrl = $this->ossClient->signUrl($this->bucket, $object, $timeout, "PUT", $options);
119+
$signedUrl = $ossClient->signUrl($this->bucket, $object, $timeout, "PUT", $options);
116120
$this->assertTrue(true);
117121
} catch (OssException $e) {
118122
print_r($e->getMessage());
119123
$this->assertFalse(true);
120124
}
121125

126+
// V4
127+
$object = "?a.file";
128+
$timeout = 3600;
129+
$options = array('Content-Type' => 'txt');
130+
$config = array(
131+
'signatureVersion' => OssClient::OSS_SIGNATURE_VERSION_V4
132+
);
133+
$ossClient = Common::getOssClient($config);
134+
try {
135+
$signedUrl = $ossClient->signUrl($this->bucket, $object, $timeout, "PUT", $options);
136+
$this->assertTrue(true);
137+
} catch (OssException $e) {
138+
print_r($e->getMessage());
139+
$this->assertFalse(true);
140+
}
122141
}
123142

124143
function testGetgenPreSignedUrlForGettingObject()

0 commit comments

Comments
 (0)