Skip to content

Commit

Permalink
兼容url校验带path
Browse files Browse the repository at this point in the history
  • Loading branch information
jojoliang committed Nov 11, 2024
1 parent 90a859c commit b0d535d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions cos.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

const (
// Version current go sdk version
Version = "0.7.57"
Version = "0.7.58"
UserAgent = "cos-go-sdk-v5/" + Version
contentTypeXML = "application/xml"
defaultServiceBaseURL = "http://service.cos.myqcloud.com"
Expand Down Expand Up @@ -86,9 +86,6 @@ func (*BaseURL) innerCheck(u *url.URL, reg *regexp.Regexp) bool {
if !strings.HasPrefix(urlStr, "https://") && !strings.HasPrefix(urlStr, "http://") {
return false
}
if strings.Count(urlStr, "/") > 2 {
return false
}
if domainSuffix.MatchString(urlStr) && !reg.MatchString(urlStr) {
return false
}
Expand Down Expand Up @@ -232,6 +229,10 @@ func NewClient(uri *BaseURL, httpClient *http.Client) *Client {
return c
}

func (c *Client) DisableURLCheck() {
c.invalidURL = false
}

type Credential struct {
SecretID string
SecretKey string
Expand Down Expand Up @@ -347,7 +348,7 @@ func (c *Client) doAPI(ctx context.Context, req *http.Request, result interface{
ctx, cancel = context.WithCancel(ctx)
defer cancel()
}
//req = req.WithContext(ctx)
req = req.WithContext(ctx)

resp, err := c.client.Do(req)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions cos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ func Test_BaseURL(t *testing.T) {
if (&BaseURL{BucketURL: u, ServiceURL: u, BatchURL: u}).Check() {
t.Errorf("BaseURL check failed: %v", u)
}
u, _ = url.Parse("https://[email protected]/myqcloud.com")
u, _ = url.Parse("https://[email protected]/.myqcloud.com")
if (&BaseURL{BucketURL: u, ServiceURL: u, BatchURL: u}).Check() {
t.Errorf("BaseURL check failed: %v", u)
}
Expand Down Expand Up @@ -349,7 +349,7 @@ func Test_BaseURL(t *testing.T) {
if (&BaseURL{BatchURL: u}).Check() {
t.Errorf("BaseURL check failed: %v", u)
}
u, _ = url.Parse("http://cos-control.ap-guangzhou.myqcloud.com/www.com")
u, _ = url.Parse("http://cos-control.ap-guangzhou.myqcloud.com")
if (&BaseURL{BatchURL: u}).Check() {
t.Errorf("BaseURL check failed: %v", u)
}
Expand Down

0 comments on commit b0d535d

Please sign in to comment.