diff --git a/caddyhttp/httpserver/tplcontext.go b/caddyhttp/httpserver/tplcontext.go index 0535a012c..92256ebf8 100644 --- a/caddyhttp/httpserver/tplcontext.go +++ b/caddyhttp/httpserver/tplcontext.go @@ -424,12 +424,13 @@ func (c Context) RandomString(minLen, maxLen int) string { return string(result) } -// Push adds a preload link in response header for server push -func (c Context) Push(link string) string { +// AddLink adds a link header in response +// see https://www.w3.org/wiki/LinkHeader +func (c Context) AddLink(link string) string { if c.responseHeader == nil { return "" } - c.responseHeader.Add("Link", "<"+link+">; rel=preload") + c.responseHeader.Add("Link", link) return "" } diff --git a/caddyhttp/httpserver/tplcontext_test.go b/caddyhttp/httpserver/tplcontext_test.go index c912f7151..77827cc33 100644 --- a/caddyhttp/httpserver/tplcontext_test.go +++ b/caddyhttp/httpserver/tplcontext_test.go @@ -877,18 +877,18 @@ func TestFiles(t *testing.T) { } } -func TestPush(t *testing.T) { +func TestAddLink(t *testing.T) { for name, c := range map[string]struct { input string expectLinks []string }{ "oneLink": { - input: `{{.Push "/test.css"}}`, + input: `{{.AddLink "; rel=preload"}}`, expectLinks: []string{"; rel=preload"}, }, "multipleLinks": { - input: `{{.Push "/test1.css"}} {{.Push "/test2.css"}}`, - expectLinks: []string{"; rel=preload", "; rel=preload"}, + input: `{{.AddLink "; rel=preload"}} {{.AddLink "; rel=meta"}}`, + expectLinks: []string{"; rel=preload", "; rel=meta"}, }, } { c := c