templates: delete ETag and Last-Modified headers (#2338)

Fixes #1920
This commit is contained in:
Wèi Cōngruì 2018-11-19 05:06:54 +08:00 committed by Matt Holt
parent 1c92557c8b
commit ce0988f48a
2 changed files with 14 additions and 0 deletions

View file

@ -110,6 +110,10 @@ func (t Templates) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error
// set the actual content length now that the template was executed
w.Header().Set("Content-Length", strconv.Itoa(buf.Len()))
// delete the headers related to cache
w.Header().Del("ETag")
w.Header().Del("Last-Modified")
// get the modification time in preparation for http.ServeContent
modTime, _ := time.Parse(http.TimeFormat, w.Header().Get("Last-Modified"))

View file

@ -70,6 +70,7 @@ func TestTemplates(t *testing.T) {
req string
respCode int
res string
bypass bool
}{
{
tpl: tmpl,
@ -113,6 +114,7 @@ func TestTemplates(t *testing.T) {
respCode: http.StatusOK,
res: `<!DOCTYPE html><html><head><title>as it is</title></head><body>{{.Include "header.html"}}</body></html>
`,
bypass: true,
},
} {
c := c
@ -135,6 +137,14 @@ func TestTemplates(t *testing.T) {
if respBody != c.res {
t.Fatalf("Test: the expected body %v is different from the response one: %v", c.res, respBody)
}
if !c.bypass {
eTag := rec.Header().Get("ETag")
lastModified := rec.Header().Get("Last-Modified")
if eTag != "" || lastModified != "" {
t.Fatalf("Test: expect a response without ETag or Last-Modified, got %v %v", eTag, lastModified)
}
}
})
}
}