Skip to content

Commit d9ddb74

Browse files
author
lewzylu
committed
support ip port
1 parent cd1b9ce commit d9ddb74

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Qcloud/Cos/BucketStyleListener.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ public static function getSubscribedEvents() {
4747
* @param Event $event Event emitted.
4848
*/
4949
public function onCommandAfterPrepare(Event $event) {
50-
5150
$command = $event['command'];
5251
$bucket = $command['Bucket'];
5352
$request = $command->getRequest();
@@ -81,7 +80,7 @@ public function onCommandAfterPrepare(Event $event) {
8180
$bucket = $bucket.'-'.$this->appId;
8281
}
8382
$request->getParams()->set('bucket', $bucket)->set('key', $key);
84-
83+
8584
$realHost = $bucket. '.' . $request->getHost();
8685
if($this->ipport != null) {
8786
$request->setHost($this->ipport);

src/Qcloud/Cos/Signature.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ public function __construct($accessKey, $secretKey) {
1111
public function __destruct() {
1212
}
1313
public function signRequest(RequestInterface $request) {
14+
$host = $request->getHeader('Host');
1415
$signTime = (string)(time() - 60) . ';' . (string)(time() + 3600);
1516
$httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) .
16-
"\n\nhost=" . $request->getHost() . "\n";
17+
"\n\nhost=" . $host . "\n";
1718
$sha1edHttpString = sha1($httpString);
1819
$stringToSign = "sha1\n$signTime\n$sha1edHttpString\n";
1920
$signKey = hash_hmac('sha1', $signTime, $this->secretKey);
@@ -27,9 +28,10 @@ public function createAuthorization(
2728
RequestInterface $request,
2829
$expires = "10 minutes"
2930
) {
31+
$host = $request->getHeader('Host');
3032
$signTime = (string)(time() - 60) . ';' . (string)(strtotime($expires));
3133
$httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getPath()) .
32-
"\n\nhost=" . $request->getHost() . "\n";
34+
"\n\nhost=" . $host . "\n";
3335
$sha1edHttpString = sha1($httpString);
3436
$stringToSign = "sha1\n$signTime\n$sha1edHttpString\n";
3537
$signKey = hash_hmac('sha1', $signTime, $this->secretKey);

0 commit comments

Comments
 (0)