6 Commits

Author SHA1 Message Date
agin719
6bc7b5256c Merge pull request #89 from agin719/common-dev
fix ci_test
2020-11-25 07:00:42 -06:00
agin719
95b127211f Merge pull request #92 from agin719/tencentyun
update version
2020-11-25 06:58:49 -06:00
jojoliang
e4b5ad8337 update version 2020-11-25 20:57:37 +08:00
agin719
1942f2303e Merge pull request #91 from agin719/tencentyun
update presignedurl && copy
2020-11-25 06:56:27 -06:00
jojoliang
9a672cde0b update presignedurl && copy 2020-11-25 20:50:47 +08:00
jojoliang
d18e8cfac2 fix ci_test 2020-10-27 19:52:55 +08:00
4 changed files with 36 additions and 18 deletions

2
cos.go
View File

@@ -22,7 +22,7 @@ import (
const (
// Version current go sdk version
Version = "0.7.11"
Version = "0.7.12"
userAgent = "cos-go-sdk-v5/" + Version
contentTypeXML = "application/xml"
defaultServiceBaseURL = "http://service.cos.myqcloud.com"

View File

@@ -56,7 +56,7 @@ const (
kBucket = "cosgosdktest-1259654469"
kRegion = "ap-guangzhou"
// 跨区域复制需要的目标存储桶地域不能与kBucket存储桶相同
// 跨区域复制需要的目标存储桶地域不能与kBucket存储桶相同, 目的存储桶需要开启多版本
kRepBucket = "cosgosdkreptest"
kRepRegion = "ap-chengdu"
@@ -85,9 +85,9 @@ func (s *CosTestSuite) SetupSuite() {
s.Region = p[2]
// Bucket name
pp := strings.Split(p[0], "-")
s.Bucket = pp[0]
s.Appid = pp[1]
pi := strings.LastIndex(p[0], "-")
s.Bucket = p[0][:pi]
s.Appid = p[0][pi+1:]
ib := &cos.BaseURL{BucketURL: bucketurl, BatchURL: batchurl}
s.Client = cos.NewClient(ib, &http.Client{
@@ -185,12 +185,12 @@ func (s *CosTestSuite) TestGetBucket() {
}
func (s *CosTestSuite) TestGetObjectVersions() {
opt := &cos.BucketGetObjectVersionsOptions {
opt := &cos.BucketGetObjectVersionsOptions{
Prefix: "中文",
MaxKeys: 3,
}
_, _, err := s.Client.Bucket.GetObjectVersions(context.Background(), opt)
assert.Nil(s.T(), err, "GetObjectVersions Failed")
_, _, err := s.Client.Bucket.GetObjectVersions(context.Background(), opt)
assert.Nil(s.T(), err, "GetObjectVersions Failed")
}
func (s *CosTestSuite) TestGetBucketLocation() {

View File

@@ -45,7 +45,7 @@ func cloneRequest(r *http.Request) *http.Request {
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent
//
// http://www.ecma-international.org/ecma-262/6.0/#sec-uri-syntax-and-semantics
func encodeURIComponent(s string) string {
func encodeURIComponent(s string, excluded ...[]byte) string {
var b bytes.Buffer
written := 0
@@ -71,6 +71,18 @@ func encodeURIComponent(s string) string {
continue
}
if len(excluded) > 0 {
conti := false
for _, ch := range excluded[0] {
if ch == c {
conti = true
break
}
}
if conti {
continue
}
}
}
b.WriteString(s[written:i])

View File

@@ -115,12 +115,12 @@ func (s *ObjectService) GetPresignedURL(ctx context.Context, httpMethod, name, a
authTime = NewAuthTime(expired)
}
authorization := newAuthorization(ak, sk, req, authTime)
sign := encodeURIComponent(authorization)
sign := encodeURIComponent(authorization, []byte{'&','='})
if req.URL.RawQuery == "" {
req.URL.RawQuery = fmt.Sprintf("sign=%s", sign)
req.URL.RawQuery = fmt.Sprintf("%s", sign)
} else {
req.URL.RawQuery = fmt.Sprintf("%s&sign=%s", req.URL.RawQuery, sign)
req.URL.RawQuery = fmt.Sprintf("%s&%s", req.URL.RawQuery, sign)
}
return req.URL, nil
@@ -256,20 +256,26 @@ func (s *ObjectService) Copy(ctx context.Context, name, sourceURL string, opt *O
}
var res ObjectCopyResult
if opt == nil {
opt = new(ObjectCopyOptions)
copyOpt := &ObjectCopyOptions{
&ObjectCopyHeaderOptions{},
&ACLHeaderOptions{},
}
if opt.ObjectCopyHeaderOptions == nil {
opt.ObjectCopyHeaderOptions = new(ObjectCopyHeaderOptions)
if opt != nil {
if opt.ObjectCopyHeaderOptions != nil {
*copyOpt.ObjectCopyHeaderOptions = *opt.ObjectCopyHeaderOptions
}
if opt.ACLHeaderOptions != nil {
*copyOpt.ACLHeaderOptions = *opt.ACLHeaderOptions
}
}
opt.XCosCopySource = u
copyOpt.XCosCopySource = u
sendOpt := sendOptions{
baseURL: s.client.BaseURL.BucketURL,
uri: "/" + encodeURIComponent(name),
method: http.MethodPut,
body: nil,
optHeader: opt,
optHeader: copyOpt,
result: &res,
}
resp, err := s.client.send(ctx, &sendOpt)