Skip to content

Commit b110e20

Browse files
author
jojoliang
committed
update
1 parent 2c500a8 commit b110e20

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

cos.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ var (
4343
hostPrefix = regexp.MustCompile(`^(http://|https://){0,1}([a-z0-9-]+-[0-9]+\.){0,1}((cos|cos-internal|cos-website|ci)\.[a-z-1]+|file)\.(myqcloud\.com|tencentcos\.cn).*$`)
4444
invalidBucketErr = fmt.Errorf("invalid bucket format, please check your cos.BaseURL")
4545

46-
switchHost = regexp.MustCompile(`([a-z0-9-]+-[0-9]+\.)((cos|cos-website)\.[a-z-1]+)\.(myqcloud\.com)(:[0-9]+){0,1}$`)
47-
oldDomainSuffix = ".myqcloud.com"
48-
newDomainSuffix = ".tencentcos.cn"
46+
switchHost = regexp.MustCompile(`([a-z0-9-]+-[0-9]+\.)((cos|cos-website)\.[a-z-1]+)\.(myqcloud\.com)(:[0-9]+){0,1}$`)
47+
accelerateDomainSuffix = "accelerate.myqcloud.com"
48+
oldDomainSuffix = ".myqcloud.com"
49+
newDomainSuffix = ".tencentcos.cn"
4950
)
5051

5152
// BaseURL 访问各 API 所需的基础 URL
@@ -365,6 +366,10 @@ func toSwitchHost(oldURL *url.URL) *url.URL {
365366
newURL, _ := url.Parse(oldURL.String())
366367
hostAndPort := strings.SplitN(newURL.Host, ":", 2)
367368
newHost := hostAndPort[0]
369+
// 加速域名不切换
370+
if strings.HasSuffix(newHost, accelerateDomainSuffix) {
371+
return oldURL
372+
}
368373
newHost = newHost[:len(newHost)-len(oldDomainSuffix)] + newDomainSuffix
369374
if len(hostAndPort) > 1 {
370375
newHost += ":" + hostAndPort[1]

cos_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,4 +222,12 @@ func Test_SwitchHost(t *testing.T) {
222222
if res.String() != want {
223223
t.Errorf("toSwitchHost failed, expect: %v, res: %v", want, res.String())
224224
}
225+
226+
u, _ = url.Parse("https://example-125000000.cos.accelerate.myqcloud.com:443/123")
227+
res = toSwitchHost(u)
228+
want = "https://example-125000000.cos.accelerate.myqcloud.com:443/123"
229+
if res.String() != want {
230+
t.Errorf("toSwitchHost failed, expect: %v, res: %v", want, res.String())
231+
}
232+
225233
}

0 commit comments

Comments
 (0)