Skip to content

Commit 9177458

Browse files
committed
Merge pull request kubernetes#2151 from claire921/r_health_http.go
Refactor formatURL in health/http.go
2 parents 5a649f2 + 51a55d3 commit 9177458

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

pkg/health/http.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ package health
1818

1919
import (
2020
"fmt"
21+
"net"
2122
"net/http"
23+
"net/url"
2224
"strconv"
2325

2426
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
@@ -76,7 +78,12 @@ func getURLParts(currentState api.PodState, container api.Container) (string, in
7678

7779
// formatURL formats a URL from args. For testability.
7880
func formatURL(host string, port int, path string) string {
79-
return fmt.Sprintf("http://%s:%d%s", host, port, path)
81+
u := url.URL{
82+
Scheme: "http",
83+
Host: net.JoinHostPort(host, strconv.Itoa(port)),
84+
Path: path,
85+
}
86+
return u.String()
8087
}
8188

8289
// DoHTTPCheck checks if a GET request to the url succeeds.

0 commit comments

Comments
 (0)