mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Middleware: Add Custom Headers to HTTP responses (#59018)
* Middleware: Add Custom Headers to HTTP responses * Update docs/sources/setup-grafana/configure-grafana/_index.md Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com> * Update conf/defaults.ini Co-authored-by: Dave Henderson <dave.henderson@grafana.com> * Update conf/sample.ini Co-authored-by: Dave Henderson <dave.henderson@grafana.com> * Update _index.md Co-authored-by: Christopher Moyer <35463610+chri2547@users.noreply.github.com> Co-authored-by: Dave Henderson <dave.henderson@grafana.com>
This commit is contained in:
@@ -77,3 +77,21 @@ func addNoCacheHeaders(w web.ResponseWriter) {
|
||||
func addXFrameOptionsDenyHeader(w web.ResponseWriter) {
|
||||
w.Header().Set("X-Frame-Options", "deny")
|
||||
}
|
||||
|
||||
func AddCustomResponseHeaders(cfg *setting.Cfg) web.Handler {
|
||||
return func(c *web.Context) {
|
||||
c.Resp.Before(func(w web.ResponseWriter) {
|
||||
if w.Written() {
|
||||
return
|
||||
}
|
||||
|
||||
for header, value := range cfg.CustomResponseHeaders {
|
||||
// do not override existing headers
|
||||
if w.Header().Get(header) != "" {
|
||||
continue
|
||||
}
|
||||
w.Header().Set(header, value)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user