mirror of
https://github.com/grafana/grafana.git
synced 2025-08-03 06:12:20 +08: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:
@ -514,6 +514,17 @@ func TestMiddlewareContext(t *testing.T) {
|
||||
cfg.AnonymousOrgRole = string(org.RoleEditor)
|
||||
})
|
||||
|
||||
middlewareScenario(t, "middleware should add custom response headers", func(t *testing.T, sc *scenarioContext) {
|
||||
sc.fakeReq("GET", "/api/").exec()
|
||||
assert.Regexp(t, "test", sc.resp.Header().Get("X-Custom-Header"))
|
||||
assert.Regexp(t, "other-test", sc.resp.Header().Get("X-Other-Header"))
|
||||
}, func(cfg *setting.Cfg) {
|
||||
cfg.CustomResponseHeaders = map[string]string{
|
||||
"X-Custom-Header": "test",
|
||||
"X-Other-Header": "other-test",
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("auth_proxy", func(t *testing.T) {
|
||||
const userID int64 = 33
|
||||
const orgID int64 = 4
|
||||
@ -811,6 +822,7 @@ func middlewareScenario(t *testing.T, desc string, fn scenarioFunc, cbs ...func(
|
||||
require.Truef(t, exists, "Views directory should exist at %q", viewsPath)
|
||||
|
||||
sc.m = web.New()
|
||||
sc.m.Use(AddCustomResponseHeaders(cfg))
|
||||
sc.m.Use(AddDefaultResponseHeaders(cfg))
|
||||
sc.m.UseMiddleware(ContentSecurityPolicy(cfg, logger))
|
||||
sc.m.UseMiddleware(web.Renderer(viewsPath, "[[", "]]"))
|
||||
|
Reference in New Issue
Block a user