Macaron: Strip down renderer middleware (#37627)

* strip down macaron renderer

* inline renderHTML

* remove IndentJSON parameter

* replace renderer with a html/template set

* fix failing test

* fix renderer paths in tests

* make template reloading even simpler

* unify ignored gzip path lookup

* fix csp middleware usage
This commit is contained in:
Serge Zaitsev
2021-08-10 13:29:46 +02:00
committed by GitHub
parent 5b575ae91f
commit 707d3536f0
14 changed files with 145 additions and 765 deletions
+1 -1
View File
@@ -118,7 +118,7 @@ func (a *CacheServer) Handler(ctx *models.ReqContext) {
if err := avatar.Encode(ctx.Resp); err != nil {
log.Warnf("avatar encode error: %v", err)
ctx.WriteHeader(500)
ctx.Resp.WriteHeader(500)
}
}
+1 -4
View File
@@ -217,10 +217,7 @@ func setupScenarioContext(t *testing.T, url string) *scenarioContext {
require.Truef(t, exists, "Views should be in %q", viewsPath)
sc.m = macaron.New()
sc.m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: viewsPath,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
sc.m.UseMiddleware(macaron.Renderer(viewsPath, "[[", "]]"))
sc.m.Use(getContextHandler(t, cfg).Middleware)
return sc
+1 -5
View File
@@ -58,11 +58,7 @@ func setupTestEnvironment(t *testing.T, cfg *setting.Cfg) (*macaron.Macaron, *HT
m := macaron.New()
m.Use(getContextHandler(t, cfg).Middleware)
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: filepath.Join(setting.StaticRootPath, "views"),
IndentJSON: true,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
m.UseMiddleware(macaron.Renderer(filepath.Join(setting.StaticRootPath, "views"), "[[", "]]"))
m.Get("/api/frontend/settings/", hs.GetFrontendSettings)
return m, hs
+3 -7
View File
@@ -335,7 +335,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
m.Use(middleware.Logger(hs.Cfg))
if hs.Cfg.EnableGzip {
m.Use(middleware.Gziper())
m.UseMiddleware(middleware.Gziper())
}
m.Use(middleware.Recovery(hs.Cfg))
@@ -354,11 +354,7 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
m.SetURLPrefix(hs.Cfg.AppSubURL)
}
m.Use(macaron.Renderer(macaron.RenderOptions{
Directory: filepath.Join(hs.Cfg.StaticRootPath, "views"),
IndentJSON: macaron.Env != macaron.PROD,
Delims: macaron.Delims{Left: "[[", Right: "]]"},
}))
m.UseMiddleware(macaron.Renderer(filepath.Join(hs.Cfg.StaticRootPath, "views"), "[[", "]]"))
// These endpoints are used for monitoring the Grafana instance
// and should not be redirected or rejected.
@@ -408,7 +404,7 @@ func (hs *HTTPServer) healthzHandler(ctx *macaron.Context) {
return
}
ctx.WriteHeader(200)
ctx.Resp.WriteHeader(200)
_, err := ctx.Resp.Write([]byte("Ok"))
if err != nil {
hs.log.Error("could not write to response", "err", err)