Skip to content

Commit bde2756

Browse files
authored
fix bug of ip-port (#131)
1 parent 5dea6bc commit bde2756

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/Qcloud/Cos/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function responseToResultTransformer(ResponseInterface $response, Request
110110
if ($command['Bucket'] != null && $response['Bucket'] == null) {
111111
$response['Bucket'] = $command['Bucket'];
112112
}
113-
$response['Location'] = $request->getUri()->getHost() . $request->getUri()->getPath();
113+
$response['Location'] = $request->getHeader("Host")[0] . $request->getUri()->getPath();
114114

115115
return $response;
116116
}

src/Qcloud/Cos/CosTransformer.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,26 @@ public function bucketStyleTransformer(CommandInterface $command, RequestInterfa
5757
}
5858
}
5959

60-
$host = $bucketname. '.cos.' . $this->config['region'] . '.' . $this->config['endpoint'];
60+
$origin_host = $bucketname. '.cos.' . $this->config['region'] . '.' . $this->config['endpoint'];
61+
$host = $origin_host;
6162
if ($this->config['ip'] != null) {
6263
$host = $this->config['ip'];
6364
if ($this->config['port'] != null) {
6465
$host = $this->config['ip'] . ":" . $this->config['port'];
6566
}
6667
}
68+
69+
6770
$path = $this->config['schema'].'://'. $host . $uri;
6871
$uri = new Uri($path);
6972
$query = $request->getUri()->getQuery();
7073
if ($uri->getQuery() != $query && $uri->getQuery() != "") {
7174
$query = $uri->getQuery() . "&" . $request->getUri()->getQuery();
7275
}
7376
$uri = $uri->withQuery($query);
74-
return $request->withUri($uri);
77+
$request = $request->withUri($uri);
78+
$request = $request->withHeader('Host', $origin_host);
79+
return $request;
7580
}
7681

7782
// format upload body

src/Qcloud/Cos/Signature.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public function signRequest(RequestInterface $request) {
2121
public function createAuthorization(RequestInterface $request, $expires = "+30 minutes") {
2222
$signTime = (string)(time() - 60) . ';' . (string)(strtotime($expires));
2323
$httpString = strtolower($request->getMethod()) . "\n" . urldecode($request->getUri()->getPath()) .
24-
"\n\nhost=" . $request->getUri()->getHost() . "\n";
24+
"\n\nhost=" . $request->getHeader("Host")[0]. "\n";
2525
$sha1edHttpString = sha1($httpString);
2626
$stringToSign = "sha1\n$signTime\n$sha1edHttpString\n";
2727
$signKey = hash_hmac('sha1', $signTime, $this->secretKey);

0 commit comments

Comments
 (0)