Merge pull request #72520 from dims/add-content-type-for-healthz-response

Ensure we set a content-type for healthz
pull/564/head
Kubernetes Prow Robot 2019-01-10 14:42:40 -08:00 committed by GitHub
commit 08d7030f62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -185,6 +185,8 @@ func handleRootHealthz(checks ...HealthzChecker) http.HandlerFunc {
return
}
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
if _, found := r.URL.Query()["verbose"]; !found {
fmt.Fprint(w, "ok")
return

View File

@ -40,6 +40,10 @@ func TestInstallHandler(t *testing.T) {
if w.Code != http.StatusOK {
t.Errorf("expected %v, got %v", http.StatusOK, w.Code)
}
c := w.Header().Get("Content-Type")
if c != "text/plain; charset=utf-8" {
t.Errorf("expected %v, got %v", "text/plain", c)
}
if w.Body.String() != "ok" {
t.Errorf("expected %v, got %v", "ok", w.Body.String())
}
@ -58,6 +62,10 @@ func TestInstallPathHandler(t *testing.T) {
if w.Code != http.StatusOK {
t.Errorf("expected %v, got %v", http.StatusOK, w.Code)
}
c := w.Header().Get("Content-Type")
if c != "text/plain; charset=utf-8" {
t.Errorf("expected %v, got %v", "text/plain", c)
}
if w.Body.String() != "ok" {
t.Errorf("expected %v, got %v", "ok", w.Body.String())
}
@ -71,6 +79,10 @@ func TestInstallPathHandler(t *testing.T) {
if w.Code != http.StatusOK {
t.Errorf("expected %v, got %v", http.StatusOK, w.Code)
}
c = w.Header().Get("Content-Type")
if c != "text/plain; charset=utf-8" {
t.Errorf("expected %v, got %v", "text/plain", c)
}
if w.Body.String() != "ok" {
t.Errorf("expected %v, got %v", "ok", w.Body.String())
}
@ -120,6 +132,10 @@ func testMultipleChecks(path string, t *testing.T) {
if w.Code != test.expectedStatus {
t.Errorf("case[%d] Expected: %v, got: %v", i, test.expectedStatus, w.Code)
}
c := w.Header().Get("Content-Type")
if c != "text/plain; charset=utf-8" {
t.Errorf("case[%d] Expected: %v, got: %v", i, "text/plain", c)
}
if w.Body.String() != test.expectedResponse {
t.Errorf("case[%d] Expected:\n%v\ngot:\n%v\n", i, test.expectedResponse, w.Body.String())
}