Skip to content

Commit 27bab7c

Browse files
authored
Merge pull request #103 from mboersma/fix-healthz-slashes
fix(http.go): don't double the slash in /healthz URL
2 parents 3ba534f + cf970af commit 27bab7c

2 files changed

Lines changed: 19 additions & 2 deletions

File tree

http.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,12 @@ your deis version is correct.`
139139
// Healthcheck can be called to see if the controller is healthy
140140
func (c *Client) Healthcheck() error {
141141
// Make a request to /healthz and expect an ok HTTP response
142-
req, err := http.NewRequest("GET", c.ControllerURL.String()+"/healthz", bytes.NewBuffer(nil))
142+
controllerURL := c.ControllerURL.String()
143+
// Don't double the last slash in the URL path
144+
if !strings.HasSuffix(controllerURL, "/") {
145+
controllerURL = controllerURL + "/"
146+
}
147+
req, err := http.NewRequest("GET", controllerURL+"healthz", bytes.NewBuffer(nil))
143148
addUserAgent(&req.Header, c.UserAgent)
144149

145150
if err != nil {

http_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,19 @@ func TestHealthcheck(t *testing.T) {
236236
server := httptest.NewServer(handler)
237237
defer server.Close()
238238

239-
deis, err := New(false, server.URL, "")
239+
// Test with a trailing slash
240+
deis, err := New(false, server.URL+"/", "")
241+
if err != nil {
242+
t.Fatal(err)
243+
}
244+
deis.UserAgent = "test"
245+
246+
if err = deis.Healthcheck(); err != nil {
247+
t.Error(err)
248+
}
249+
250+
// Test without a trailing slash
251+
deis, err = New(false, server.URL, "")
240252
if err != nil {
241253
t.Fatal(err)
242254
}

0 commit comments

Comments
 (0)