Skip to content

Commit

Permalink
fix scheme
Browse files Browse the repository at this point in the history
Signed-off-by: Cabinfever_B <[email protected]>
  • Loading branch information
CabinfeverB committed Mar 8, 2024
1 parent 6438a65 commit 55b6c9a
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions client/pd_service_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -1131,24 +1131,21 @@ func addrsToUrls(addrs []string, tlsCfg *tls.Config) []string {
// Add default schema "http://" to addrs.
urls := make([]string, 0, len(addrs))
for _, addr := range addrs {
addr = addrToUrl(addr, tlsCfg)
urls = append(urls, addr)
urls = append(urls, addrToUrl(addr, tlsCfg))
}
return urls
}

func addrToUrl(addr string, tlsCfg *tls.Config) string {
if tlsCfg == nil {
if strings.HasPrefix(addr, httpsScheme) {
addr = strings.TrimPrefix(addr, httpsScheme)
addr = fmt.Sprintf("%s%s", httpScheme, addr)
addr = fmt.Sprintf("%s%s", httpScheme, strings.TrimPrefix(addr, httpsScheme))
} else if !strings.HasPrefix(addr, httpScheme) {
addr = fmt.Sprintf("%s%s", httpScheme, addr)
}
} else {
if strings.HasPrefix(addr, httpScheme) {
addr = strings.TrimPrefix(addr, httpScheme)
addr = fmt.Sprintf("%s%s", httpsScheme, addr)
addr = fmt.Sprintf("%s%s", httpsScheme, strings.TrimPrefix(addr, httpScheme))
} else if !strings.HasPrefix(addr, httpsScheme) {
addr = fmt.Sprintf("%s%s", httpsScheme, addr)
}
Expand Down

0 comments on commit 55b6c9a

Please sign in to comment.