Commit 0b32f49e authored by Geoff Simmons's avatar Geoff Simmons

Don't set a Content-Type for empty responses in the REST API.

parent 3e50b558
......@@ -92,7 +92,6 @@ type healthzHndlr struct {
func (h *healthzHndlr) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
now := time.Now()
resp.Header().Set("Content-Type", "text/plain")
resp.Header().Set("Content-Length", "0")
resp.Header().Set("Cache-Control", "no-store")
status := http.StatusTeapot
......@@ -121,7 +120,6 @@ func (h *pemsHndlr) allPems(
req *http.Request,
now time.Time,
) {
resp.Header().Set("Content-Type", "text/plain")
resp.Header().Set("Content-Length", "0")
resp.WriteHeader(http.StatusNotImplemented)
reqLog(h.log, req, now, http.StatusNotImplemented, 0)
......@@ -135,7 +133,6 @@ func (h *pemsHndlr) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
return
}
resp.Header().Set("Content-Type", "text/plain")
resp.Header().Set("Content-Length", "0")
status := http.StatusTeapot
bytes := 0
......
......@@ -69,12 +69,6 @@ func TestHealthz(t *testing.T) {
rr.Result().Header.Get("Application-Version"),
version)
}
textPlain := "text/plain"
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("GET /v1/healthz Content-Type: got %s want %s",
rr.Result().Header.Get("Content-Type"),
textPlain)
}
noStore := "no-store"
if rr.Result().Header.Get("Cache-Control") != noStore {
t.Errorf("GET /v1/healthz Cache-Control: got %s want %s",
......@@ -113,7 +107,6 @@ func TestHealthz405(t *testing.T) {
version: version,
log: &logrus.Logger{Out: ioutil.Discard},
}
textPlain := "text/plain"
noStore := "no-store"
methods := []string{
......@@ -134,11 +127,6 @@ func TestHealthz405(t *testing.T) {
method, rr.Result().Header.
Get("Content-Length"))
}
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("%s /v1/healthz Content-Type: got %s want %s",
method, rr.Result().Header.Get("Content-Type"),
textPlain)
}
if rr.Result().Header.Get("Cache-Control") != noStore {
t.Errorf("%s /v1/healthz Cache-Control: got %s want %s",
method, rr.Result().Header.Get("Cache-Control"),
......@@ -327,13 +315,6 @@ func TestPutPem(t *testing.T) {
t.Errorf("file contents after PUT: got %q want %q", contents,
expected)
}
textPlain := "text/plain"
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("PUT /v1/pems/ns1/secret1 Content-Type: "+
"got %s want %s",
rr.Result().Header.Get("Content-Type"),
textPlain)
}
if rr.Result().Header.Get("Content-Length") != "0" {
t.Errorf("PUT /v1/pems/ns1/secret1 Content-Length: "+
"got %s want 0",
......@@ -347,12 +328,6 @@ func TestPutPem(t *testing.T) {
t.Errorf("2nd PUT /v1/pems/ns1/secret1 status: got %d want %d",
rr.Code, http.StatusNoContent)
}
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("PUT /v1/pems/ns1/secret1 Content-Type: "+
"got %s want %s",
rr.Result().Header.Get("Content-Type"),
textPlain)
}
if rr.Result().Header.Get("Content-Length") != "" {
t.Errorf("2nd PUT /v1/pems/ns1/secret1 Content-Length: "+
"got %s want empty",
......@@ -366,12 +341,6 @@ func TestPutPem(t *testing.T) {
t.Errorf("PUT /v1/pems/foo/bar status: got %d want %d",
rr.Code, http.StatusNotFound)
}
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("PUT /v1/pems/foo/bar Content-Type: "+
"got %s want %s",
rr.Result().Header.Get("Content-Type"),
textPlain)
}
if rr.Result().Header.Get("Content-Length") != "0" {
t.Errorf("PUT /v1/pems/foo/bar Content-Length: "+
"got %s want 0",
......@@ -580,13 +549,6 @@ func TestPostPem(t *testing.T) {
t.Errorf("file contents after POST: got %q want %q", contents,
expected)
}
textPlain := "text/plain"
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("POST /v1/pems/ns1/secret1 Content-Type: "+
"got %s want %s",
rr.Result().Header.Get("Content-Type"),
textPlain)
}
if rr.Result().Header.Get("Content-Length") != "0" {
t.Errorf("POST /v1/pems/ns1/secret1 Content-Length: "+
"got %s want 0",
......@@ -600,12 +562,6 @@ func TestPostPem(t *testing.T) {
t.Errorf("2nd POST /v1/pems/ns1/secret1 status: got %d want %d",
rr.Code, http.StatusConflict)
}
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("POST /v1/pems/ns1/secret1 Content-Type: "+
"got %s want %s",
rr.Result().Header.Get("Content-Type"),
textPlain)
}
if rr.Result().Header.Get("Content-Length") != "0" {
t.Errorf("2nd POST /v1/pems/ns1/secret1 Content-Length: "+
"got %s want 0",
......@@ -678,13 +634,6 @@ func TestDeletePem(t *testing.T) {
if files.Check("ns1", "secret1", "", "") {
t.Error("files.Check() after DELETE: got true want false")
}
textPlain := "text/plain"
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("DELETE /v1/pems/ns1/secret1 Content-Type: "+
"got %s want %s",
rr.Result().Header.Get("Content-Type"),
textPlain)
}
if rr.Result().Header.Get("Content-Length") != "" {
t.Errorf("DELETE /v1/pems/ns1/secret1 Content-Length: "+
"got %s want empty",
......@@ -756,7 +705,6 @@ func TestGetPem(t *testing.T) {
crtGetter: getter,
}
textPlain := "text/plain"
for _, method := range []string{http.MethodGet, http.MethodHead} {
req := httptest.NewRequest(method, "/v1/pems/ns/name", nil)
rr := httptest.NewRecorder()
......@@ -770,12 +718,6 @@ func TestGetPem(t *testing.T) {
"got %s want 0", method,
rr.Result().Header.Get("Content-Length"))
}
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("%s /v1/pems/ns/name Content-Type: "+
"got %s want %s", method,
rr.Result().Header.Get("Content-Type"),
textPlain)
}
}
}
......@@ -799,7 +741,6 @@ func TestPem405(t *testing.T) {
crtGetter: getter,
}
textPlain := "text/plain"
methods := []string{
http.MethodPatch, http.MethodConnect, http.MethodOptions,
http.MethodTrace, "BAZQUUX",
......@@ -817,12 +758,6 @@ func TestPem405(t *testing.T) {
"got %s want 0", method,
rr.Result().Header.Get("Content-Length"))
}
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("%s /v1/pems/ns/name Content-Type: "+
"got %s want %s", method,
rr.Result().Header.Get("Content-Type"),
textPlain)
}
}
}
......@@ -846,7 +781,6 @@ func TestAllPem(t *testing.T) {
crtGetter: getter,
}
textPlain := "text/plain"
methods := []string{
http.MethodGet, http.MethodHead, http.MethodPost,
http.MethodPut, http.MethodPatch, http.MethodDelete,
......@@ -867,10 +801,5 @@ func TestAllPem(t *testing.T) {
method, rr.Result().Header.
Get("Content-Length"))
}
if rr.Result().Header.Get("Content-Type") != textPlain {
t.Errorf("%s /v1/pems Content-Type: got %s want %s",
method, rr.Result().Header.Get("Content-Type"),
textPlain)
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment