Commit ce0988f4 authored by Wèi Cōngruì's avatar Wèi Cōngruì Committed by Matt Holt

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

Fixes #1920
parent 1c92557c
......@@ -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"))
......
......@@ -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)
}
}
})
}
}
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