Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tencent endpoint #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions tencent/tencent.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
package tencent

import (
"os"
"github.com/qor/oss"
"io"
"bytes"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"os"
"path/filepath"
"time"
"errors"
"strings"
"bytes"
"regexp"
"net/url"
"strings"
"time"

"github.com/qor/oss"
)

var _ oss.StorageInterface = (*Client)(nil)
Expand Down Expand Up @@ -73,7 +74,7 @@ func (client Client) GetStream(path string) (io.ReadCloser, error) {
return nil, err
}
if resp.StatusCode != http.StatusOK {
return nil,errors.New("get file fail")
return nil, errors.New("get file fail")
}
return resp.Body, nil
}
Expand All @@ -98,7 +99,7 @@ func (client Client) Put(path string, body io.Reader) (*oss.Object, error) {
if err != nil {
return nil, err
}
req.Header.Set("Host", client.GetEndpoint())
req.Header.Set("Host", client.getHost())
req.Header.Set("Authorization", client.authorization(req))
result, err := client.Client.Do(req)
if err != nil {
Expand All @@ -125,7 +126,7 @@ func (client Client) Delete(path string) error {
if err != nil {
return err
}
req.Header.Set("Host", client.GetEndpoint())
req.Header.Set("Host", client.getHost())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of returning the URL in a fixed format rather than the current GetEndpoint implementation?

Actually, could you describe what is the problem and how you fixed it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req.Header.Set("Host", client.getHost())

腾讯 cos host字段值设置成加速域名地址时报错,host只能是xxxx-123456.cos.ap-guangzhou.myqcloud.com格式的

client.GetEndpoint() 方法返回的是用户设置地址既可以是xxxx-123456.cos.ap-guangzhou.myqcloud.com 格式的,也可以是自己加速域名的地址。

client.getHost()方法返回的是xxxx-123456.cos.ap-guangzhou.myqcloud.com 格式的地址

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

既然 client.GetEndpoint() 可以被用户设置 那看起来已经足以满足要求了?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

req.Header.Set("Host", client.GetEndpoint()) 不能使用用户设置的域名

req.Header.Set("Authorization", client.authorization(req))
result, err := client.Client.Do(req)
if err != nil {
Expand Down Expand Up @@ -166,7 +167,14 @@ func (client Client) GetEndpoint() string {
return fmt.Sprintf("%s.cos.%s.myqcloud.com", client.Config.Bucket, client.Config.Region)
}

func (client Client) getHost() string {
return fmt.Sprintf("%s.cos.%s.myqcloud.com", client.Config.Bucket, client.Config.Region)
}

func (client Client) GetURL(path string) (string, error) {
if client.Config.Endpoint != "" {
return fmt.Sprintf("%s/%s", client.Config.Endpoint, client.ToRelativePath(path)), nil
}
return fmt.Sprintf("%s%s", client.getUrl(), client.ToRelativePath(path)), nil
}

Expand Down