Optionally return rel="canonical" header (#542)

* set rel="canonical" header

* check scheme before setting canonical headers, add documentation
This commit is contained in:
snowcall
2021-03-09 14:08:22 +03:00
committed by GitHub
parent 768cb1e868
commit 56d3f6d897
3 changed files with 11 additions and 0 deletions

View File

@@ -67,6 +67,14 @@ func respondWithImage(ctx context.Context, reqID string, r *http.Request, rw htt
rw.Header().Set("Content-Type", po.Format.Mime())
rw.Header().Set("Content-Disposition", contentDisposition)
if conf.SetCanonicalHeader {
origin := getImageURL(ctx)
if strings.HasPrefix(origin, "https://") || strings.HasPrefix(origin, "http://") {
linkHeader := fmt.Sprintf(`<%s>; rel="canonical"`, origin)
rw.Header().Set("Link", linkHeader)
}
}
var cacheControl, expires string
if conf.CacheControlPassthrough {