Skip to content

Commit

Permalink
templates: delete ETag and Last-Modified headers (#2338)
Browse files Browse the repository at this point in the history
Fixes #1920
  • Loading branch information
crvv authored and mholt committed Nov 18, 2018
1 parent 1c92557 commit ce0988f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions caddyhttp/templates/templates.go
Expand Up @@ -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"))

Expand Down
10 changes: 10 additions & 0 deletions caddyhttp/templates/templates_test.go
Expand Up @@ -70,6 +70,7 @@ func TestTemplates(t *testing.T) {
req string
respCode int
res string
bypass bool
}{
{
tpl: tmpl,
Expand Down Expand Up @@ -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
Expand All @@ -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)
}
}
})
}
}

0 comments on commit ce0988f

Please sign in to comment.