Ensure we set a content-type for healthz

Change-Id: I453b1433c69bf26c28da873dbdd1ac25006b8d60

Co-Authored-By: Tim Allclair (St. Clair) <tallclair@google.com>
This commit is contained in:
Davanum Srinivas 2019-01-03 10:05:58 -05:00
parent 76e9089d0e
commit eedb70355a
No known key found for this signature in database
GPG Key ID: 80D83A796103BF59
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())
}