Ejemplo n.º 1
0
 /**
  * @return CorsConfig
  */
 protected function parseDataFromResponse()
 {
     $content = $this->rawResponse->body;
     $config = new CorsConfig();
     $config->parseFromXml($content);
     return $config;
 }
Ejemplo n.º 2
0
 /**
  * 在指定的bucket上设定一个跨域资源共享(CORS)的规则,如果原规则存在则覆盖原规则
  *
  * @param string     $bucket     bucket名称
  * @param CorsConfig $corsConfig 跨域资源共享配置,具体规则参见SDK文档
  * @param array      $options    array
  *
  * @throws Exception
  * @return null
  */
 public function putBucketCors($bucket, $corsConfig, $options = null)
 {
     $this->precheckCommon($bucket, null, $options, false);
     $options[self::OSS_BUCKET] = $bucket;
     $options[self::OSS_METHOD] = self::OSS_HTTP_PUT;
     $options[self::OSS_OBJECT] = '/';
     $options[self::OSS_SUB_RESOURCE] = 'cors';
     $options[self::OSS_CONTENT_TYPE] = 'application/xml';
     $options[self::OSS_CONTENT] = $corsConfig->serializeToXml();
     $response = $this->auth($options);
     $result = new PutSetDeleteResult($response);
     return $result->getData();
 }
Ejemplo n.º 3
0
 public function testCreateCorsConfigFromScratch()
 {
     $corsConfig = new CorsConfig();
     $rule = new CorsRule();
     $rule->addAllowedHeader("x-oss-test");
     $rule->addAllowedHeader("x-oss-test2");
     $rule->addAllowedHeader("x-oss-test2");
     $rule->addAllowedHeader("x-oss-test3");
     $rule->addAllowedOrigin("http://www.b.com");
     $rule->addAllowedOrigin("http://www.a.com");
     $rule->addAllowedOrigin("http://www.a.com");
     $rule->addAllowedMethod("GET");
     $rule->addAllowedMethod("PUT");
     $rule->addAllowedMethod("POST");
     $rule->addExposeHeader("x-oss-test1");
     $rule->addExposeHeader("x-oss-test1");
     $rule->addExposeHeader("x-oss-test2");
     $rule->setMaxAgeSeconds(10);
     $corsConfig->addRule($rule);
     $this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml($corsConfig->serializeToXml()));
     $this->assertEquals($this->cleanXml($this->validXml2), $this->cleanXml(strval($corsConfig)));
 }
 public function testBucket()
 {
     $corsConfig = new CorsConfig();
     $rule = new CorsRule();
     $rule->addAllowedHeader("x-oss-test");
     $rule->addAllowedHeader("x-oss-test2");
     $rule->addAllowedHeader("x-oss-test2");
     $rule->addAllowedHeader("x-oss-test3");
     $rule->addAllowedOrigin("http://www.b.com");
     $rule->addAllowedOrigin("http://www.a.com");
     $rule->addAllowedOrigin("http://www.a.com");
     $rule->addAllowedMethod("GET");
     $rule->addAllowedMethod("PUT");
     $rule->addAllowedMethod("POST");
     $rule->addExposeHeader("x-oss-test1");
     $rule->addExposeHeader("x-oss-test1");
     $rule->addExposeHeader("x-oss-test2");
     $rule->setMaxAgeSeconds(10);
     $corsConfig->addRule($rule);
     $rule = new CorsRule();
     $rule->addAllowedHeader("x-oss-test");
     $rule->addAllowedMethod("GET");
     $rule->addAllowedOrigin("http://www.b.com");
     $rule->addExposeHeader("x-oss-test1");
     $rule->setMaxAgeSeconds(110);
     $corsConfig->addRule($rule);
     try {
         $this->ossClient->putBucketCors($this->bucket, $corsConfig);
     } catch (Exception $e) {
         $this->assertFalse(true);
     }
     try {
         $object = "cors/test.txt";
         $this->ossClient->putObject($this->bucket, $object, file_get_contents(__FILE__));
         $headers = $this->ossClient->optionsObject($this->bucket, $object, "http://www.a.com", "GET", "", null);
         $this->assertNotEmpty($headers);
     } catch (Exception $e) {
         var_dump($e->getMessage());
     }
     try {
         sleep(1);
         $corsConfig2 = $this->ossClient->getBucketCors($this->bucket);
         $this->assertNotNull($corsConfig2);
         $this->assertEquals($corsConfig->serializeToXml(), $corsConfig2->serializeToXml());
     } catch (Exception $e) {
         $this->assertFalse(true);
     }
     try {
         $this->ossClient->deleteBucketCors($this->bucket);
     } catch (Exception $e) {
         $this->assertFalse(true);
     }
     try {
         sleep(5);
         $corsConfig3 = $this->ossClient->getBucketCors($this->bucket);
         $this->assertNotNull($corsConfig3);
         $this->assertNotEquals($corsConfig->serializeToXml(), $corsConfig3->serializeToXml());
     } catch (Exception $e) {
         $this->assertFalse(true);
     }
 }