Skip to content

Commit edd430d

Browse files
authored
Merge pull request #317 from tencentyun/feature_jojoliang_ef5f22f8
Feature jojoliang ef5f22f8
2 parents 6b10a52 + 8929400 commit edd430d

File tree

7 files changed

+559
-12
lines changed

7 files changed

+559
-12
lines changed

bucket_origin.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ type BucketOriginCondition struct {
3030

3131
type BucketOriginParameter struct {
3232
Protocol string `xml:"Protocol,omitempty"`
33-
FollowQueryString bool `xml:"FollowQueryString,omitempty"`
33+
FollowQueryString *bool `xml:"FollowQueryString,omitempty"`
3434
HttpHeader *BucketOriginHttpHeader `xml:"HttpHeader,omitempty"`
35-
FollowRedirection bool `xml:"FollowRedirection,omitempty"`
35+
FollowRedirection *bool `xml:"FollowRedirection,omitempty"`
3636
HttpRedirectCode string `xml:"HttpRedirectCode,omitempty"`
37-
CopyOriginData bool `xml:"CopyOriginData,omitempty"`
37+
CopyOriginData *bool `xml:"CopyOriginData,omitempty"`
3838
}
3939

4040
type BucketOriginHttpHeader struct {
4141
// 目前还不支持 FollowAllHeaders
42-
FollowAllHeaders bool `xml:"FollowAllHeaders,omitempty"`
42+
FollowAllHeaders *bool `xml:"FollowAllHeaders,omitempty"`
4343
NewHttpHeaders []OriginHttpHeader `xml:"NewHttpHeaders>Header,omitempty"`
4444
FollowHttpHeaders []OriginHttpHeader `xml:"FollowHttpHeaders>Header,omitempty"`
4545
ForbidFollowHeaders []OriginHttpHeader `xml:"ForbidFollowHeaders>Header,omitempty"`

bucket_origin_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestBucketService_GetOrigin(t *testing.T) {
2929
</OriginCondition>
3030
<OriginParameter>
3131
<Protocol>HTTP</Protocol>
32-
<FollowQueryString>true</FollowQueryString>
32+
<FollowQueryString>false</FollowQueryString>
3333
<HttpHeader>
3434
<NewHttpHeaders>
3535
<Header>
@@ -75,7 +75,7 @@ func TestBucketService_GetOrigin(t *testing.T) {
7575
},
7676
OriginParameter: &BucketOriginParameter{
7777
Protocol: "HTTP",
78-
FollowQueryString: true,
78+
FollowQueryString: Bool(false),
7979
HttpHeader: &BucketOriginHttpHeader{
8080
FollowHttpHeaders: []OriginHttpHeader{
8181
{
@@ -89,7 +89,7 @@ func TestBucketService_GetOrigin(t *testing.T) {
8989
},
9090
},
9191
},
92-
FollowRedirection: true,
92+
FollowRedirection: Bool(true),
9393
HttpRedirectCode: "302",
9494
},
9595
OriginInfo: &BucketOriginInfo{
@@ -123,7 +123,7 @@ func TestBucketService_PutOrigin(t *testing.T) {
123123
},
124124
OriginParameter: &BucketOriginParameter{
125125
Protocol: "HTTP",
126-
FollowQueryString: true,
126+
FollowQueryString: Bool(true),
127127
HttpHeader: &BucketOriginHttpHeader{
128128
FollowHttpHeaders: []OriginHttpHeader{
129129
{
@@ -137,7 +137,7 @@ func TestBucketService_PutOrigin(t *testing.T) {
137137
},
138138
},
139139
},
140-
FollowRedirection: true,
140+
FollowRedirection: Bool(true),
141141
HttpRedirectCode: "302",
142142
},
143143
OriginInfo: &BucketOriginInfo{

cos.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626

2727
const (
2828
// Version current go sdk version
29-
Version = "0.7.65"
29+
Version = "0.7.66"
3030
UserAgent = "cos-go-sdk-v5/" + Version
3131
contentTypeXML = "application/xml"
3232
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
@@ -478,6 +478,16 @@ func (c *Client) CheckRetrieable(u *url.URL, resp *Response, err error, secondLa
478478
if err != nil && err != invalidBucketErr {
479479
// 不重试
480480
if resp != nil && resp.StatusCode < 500 {
481+
if c.Conf.RetryOpt.AutoSwitchHost {
482+
if resp.StatusCode == 301 || resp.StatusCode == 302 || resp.StatusCode == 307 {
483+
if resp.Header.Get("X-Cos-Request-Id") == "" {
484+
res = toSwitchHost(u)
485+
if res != u {
486+
return res, true
487+
}
488+
}
489+
}
490+
}
481491
return res, false
482492
}
483493
if c.Conf.RetryOpt.AutoSwitchHost && secondLast {

example/bucket/origin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func main() {
5858
},
5959
OriginParameter: &cos.BucketOriginParameter{
6060
Protocol: "FOLLOW",
61-
FollowQueryString: true,
61+
FollowQueryString: cos.Bool(true),
6262
HttpHeader: &cos.BucketOriginHttpHeader{
6363
NewHttpHeaders: []cos.OriginHttpHeader{
6464
{
@@ -72,7 +72,7 @@ func main() {
7272
},
7373
},
7474
},
75-
FollowRedirection: true,
75+
FollowRedirection: cos.Bool(true),
7676
},
7777
OriginInfo: &cos.BucketOriginInfo{
7878
HostInfo: &cos.BucketOriginHostInfo{

helper.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,3 +474,7 @@ func GetBucketRegionFromUrl(u *url.URL) (string, string) {
474474
}
475475
return vec[0], vec[2]
476476
}
477+
478+
func Bool(v bool) *bool {
479+
return &v
480+
}

object.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -505,6 +505,7 @@ func (s *ObjectService) Put(ctx context.Context, name string, r io.Reader, uopt
505505
method: http.MethodPut,
506506
body: reader,
507507
optHeader: opt,
508+
isRetry: nr > 0,
508509
}
509510

510511
// 把上一次错误记录下来

0 commit comments

Comments
 (0)