Skip to content

Commit

Permalink
fix: check endpoint prefix in qiniu.go (#17)
Browse files Browse the repository at this point in the history
* Update qiniu.go

"/tmp" into os.TempDir()

* fix: validate endpoint protocol prefix in qiniu configuration

Ensure the configuration's endpoint starts with either 'http://' or 'https://'. This validation check prevents errors related to invalid endpoint formats, enhancing the robustness of the connection setup process.

* Update qiniu.go

---------

Co-authored-by: Eric Luo <[email protected]>
  • Loading branch information
Infinityay and hsluoyz authored Mar 7, 2024
1 parent 5cbbf3b commit 8c2ae92
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion qiniu/qiniu.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ func New(config *Config) (*Client, error) {
if len(config.Endpoint) == 0 {
return nil, fmt.Errorf("endpoint must be provided.")
}

if !strings.HasPrefix(config.Endpoint, "http://") && !strings.HasPrefix(config.Endpoint, "https://") {
return nil, fmt.Errorf("endpoint must start with http:// or https://")
}
client.storageCfg.UseHTTPS = config.UseHTTPS
client.storageCfg.UseCdnDomains = config.UseCdnDomains
client.bucketManager = storage.NewBucketManager(client.mac, &client.storageCfg)
Expand All @@ -92,7 +96,7 @@ func (client Client) SetPutPolicy(putPolicy *storage.PutPolicy) {
func (client Client) Get(path string) (file *os.File, err error) {
readCloser, err := client.GetStream(path)

if file, err = ioutil.TempFile("/tmp", "qiniu"); err == nil {
if file, err = ioutil.TempFile(os.TempDir(), "qiniu"); err == nil {
defer readCloser.Close()
_, err = io.Copy(file, readCloser)
file.Seek(0, 0)
Expand Down

0 comments on commit 8c2ae92

Please sign in to comment.