From 18751cfb43a99f75ce4d60da3ceca05b4bb24e20 Mon Sep 17 00:00:00 2001 From: lewzylu <327874225@qq.com> Date: Thu, 14 Sep 2017 12:09:39 +0800 Subject: [PATCH] fix host bug --- cos-autoloader.php | 3 +- src/Qcloud/Cos/BucketStyleListener.php | 6 +++- src/Qcloud/Cos/Client.php | 1 - src/Qcloud/Cos/GetServiceListener.php | 49 -------------------------- src/Qcloud/Cos/Service.php | 4 +-- 5 files changed, 8 insertions(+), 55 deletions(-) delete mode 100644 src/Qcloud/Cos/GetServiceListener.php diff --git a/cos-autoloader.php b/cos-autoloader.php index 6d872e18..7d0efb83 100644 --- a/cos-autoloader.php +++ b/cos-autoloader.php @@ -248,7 +248,6 @@ 'Qcloud\Cos\Exception\ServiceResponseException' => 'src/Qcloud/Cos/Exception/ServiceResponseException.php', 'Qcloud\Cos\ExceptionListener' => 'src/Qcloud/Cos/ExceptionListener.php', 'Qcloud\Cos\ExceptionParser' => 'src/Qcloud/Cos/ExceptionParser.php', - 'Qcloud\Cos\GetServiceListener' => 'src/Qcloud/Cos/GetServiceListener.php', 'Qcloud\Cos\MultipartUpload' => 'src/Qcloud/Cos/MultipartUpload.php', 'Qcloud\Cos\Service' => 'src/Qcloud/Cos/Service.php', 'Qcloud\Cos\Signature' => 'src/Qcloud/Cos/Signature.php', @@ -278,4 +277,4 @@ if (isset($mapping[$class])) { require $mapping[$class]; } -}, true); \ No newline at end of file +}, true); diff --git a/src/Qcloud/Cos/BucketStyleListener.php b/src/Qcloud/Cos/BucketStyleListener.php index 11460810..e1a1caf3 100644 --- a/src/Qcloud/Cos/BucketStyleListener.php +++ b/src/Qcloud/Cos/BucketStyleListener.php @@ -28,7 +28,11 @@ public function onCommandAfterPrepare(Event $event) { $command = $event['command']; $bucket = $command['Bucket']; $request = $command->getRequest(); - + if ($command->getName() == 'ListBuckets') + { + $request->setHost('service.cos.myqcloud.com'); + return ; + } if ($key = $command['Key']) { // Modify the command Key to account for the {/Key*} explosion into an array if (is_array($key)) { diff --git a/src/Qcloud/Cos/Client.php b/src/Qcloud/Cos/Client.php index 689be566..dd0e7694 100644 --- a/src/Qcloud/Cos/Client.php +++ b/src/Qcloud/Cos/Client.php @@ -52,7 +52,6 @@ public function __construct($config) { $this->setUserAgent('cos-php-sdk-v5/' . Client::VERSION, true); $this->addSubscriber(new ExceptionListener()); -$this->addSubscriber(new GetServiceListener()); $this->addSubscriber(new TokenListener($this->token)); $this->addSubscriber(new SignatureListener($this->secretId, $this->secretKey)); $this->addSubscriber(new BucketStyleListener($this->appId)); diff --git a/src/Qcloud/Cos/GetServiceListener.php b/src/Qcloud/Cos/GetServiceListener.php deleted file mode 100644 index 11b9639d..00000000 --- a/src/Qcloud/Cos/GetServiceListener.php +++ /dev/null @@ -1,49 +0,0 @@ - array('onRequestBeforeSend', -253)); - } - - /** - * Signs requests before they are sent - * - * @param Event $event Event emitted - */ - public function onRequestBeforeSend(Event $event) { - #print_r($event['request']); - if($event['request']->getPath() == '/ASDWQdsawqefdQWESDFFSDFSADCXSVSDQWERTREGERTYTHDF' && $event['request']->getMethod() == 'GET') - { - $event['request']->setPath('/'); - $event['request']->setUrl('http://service.cos.myqcloud.com'); - } -/* - if(!$this->credentials instanceof NullCredentials) { - $this->signature->signRequest($event['request'], $this->credentials); - } -*/ - } -} diff --git a/src/Qcloud/Cos/Service.php b/src/Qcloud/Cos/Service.php index 110aaabe..3b3fa472 100644 --- a/src/Qcloud/Cos/Service.php +++ b/src/Qcloud/Cos/Service.php @@ -13,7 +13,7 @@ public static function getService() { 'operations' => array( 'ListBuckets' => array( 'httpMethod' => 'GET', - 'uri' => '/ASDWQdsawqefdQWESDFFSDFSADCXSVSDQWERTREGERTYTHDF', + 'uri' => '/', 'class' => 'Qcloud\\Cos\\Command', 'responseClass' => 'ListBucketsOutput', 'responseType' => 'model', @@ -517,7 +517,7 @@ public static function getService() { 'RequestPayer' => array( 'type' => 'string', 'location' => 'header', - 'sentAs' => 'x-amz-request-payer', + 'sentAs' => 'x-cos-request-payer', ), 'command.expects' => array( 'static' => true,