|
@@ -2,26 +2,20 @@ package dpcore
|
|
|
|
|
|
import (
|
|
|
"net/url"
|
|
|
- "strings"
|
|
|
)
|
|
|
|
|
|
-func replaceLocationHost(urlString, newHost string) (string, error) {
|
|
|
- parsedURL, err := url.Parse(urlString)
|
|
|
+func replaceLocationHost(urlString string, newHost string, useTLS bool) (string, error) {
|
|
|
+ u, err := url.Parse(urlString)
|
|
|
if err != nil {
|
|
|
return "", err
|
|
|
}
|
|
|
|
|
|
- // Extract the port number from the host string (if it exists)
|
|
|
- hostParts := strings.Split(parsedURL.Host, ":")
|
|
|
- var newHostString string
|
|
|
- if len(hostParts) > 1 {
|
|
|
- newHostString = newHost + ":" + hostParts[1]
|
|
|
+ if useTLS {
|
|
|
+ u.Scheme = "https"
|
|
|
} else {
|
|
|
- newHostString = newHost
|
|
|
+ u.Scheme = "http"
|
|
|
}
|
|
|
|
|
|
- // Set the new host string
|
|
|
- parsedURL.Host = newHostString
|
|
|
-
|
|
|
- return parsedURL.String(), nil
|
|
|
+ u.Host = newHost
|
|
|
+ return u.String(), nil
|
|
|
}
|