mirror of https://github.com/coder/coder.git
fix(cli/server): do not redirect /healthz (#12080)
This commit is contained in:
parent
92b2e26a48
commit
2b307c7c4e
|
@ -1991,6 +1991,13 @@ func redirectToAccessURL(handler http.Handler, accessURL *url.URL, tunnel bool,
|
|||
http.Redirect(w, r, accessURL.String(), http.StatusTemporaryRedirect)
|
||||
}
|
||||
|
||||
// Exception: /healthz
|
||||
// Kubernetes doesn't like it if you redirect your healthcheck or liveness check endpoint.
|
||||
if r.URL.Path == "/healthz" {
|
||||
handler.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
// Exception: DERP
|
||||
// We use this endpoint when creating a DERP-mesh in the enterprise version to directly
|
||||
// dial other Coderd derpers. Redirecting to the access URL breaks direct dial since the
|
||||
|
|
|
@ -685,11 +685,17 @@ func TestServer(t *testing.T) {
|
|||
require.Equal(t, c.expectRedirect, resp.Header.Get("Location"))
|
||||
}
|
||||
|
||||
// We should never readirect /healthz
|
||||
respHealthz, err := client.Request(ctx, http.MethodGet, "/healthz", nil)
|
||||
require.NoError(t, err)
|
||||
defer respHealthz.Body.Close()
|
||||
require.Equal(t, http.StatusOK, respHealthz.StatusCode, "/healthz should never redirect")
|
||||
|
||||
// We should never redirect DERP
|
||||
respDERP, err := client.Request(ctx, http.MethodGet, "/derp", nil)
|
||||
require.NoError(t, err)
|
||||
defer respDERP.Body.Close()
|
||||
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode)
|
||||
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode, "/derp should never redirect")
|
||||
}
|
||||
|
||||
// Verify TLS
|
||||
|
|
Loading…
Reference in New Issue