Skip to content

Commit

Permalink
fix: validate endpoint protocol prefix in qiniu configuration
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Infinityay authored Mar 7, 2024
1 parent 0f588bc commit 6af4e10
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions 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.")
}
// 检查Endpoint是否以http://或https://开头
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 Down

0 comments on commit 6af4e10

Please sign in to comment.