Exemplo n.º 1
0
func BeforeRouter(c *context.Context) {
	ok := miniprofiler.Enable(c.Request)
	if ok && strings.HasPrefix(c.Request.URL.Path, miniprofiler.PATH) {
		miniprofiler.MiniProfilerHandler(c.ResponseWriter, c.Request)
		return
	}
	p := miniprofiler.NewProfile(c.ResponseWriter, c.Request, c.Request.URL.Path)
	c.Input.Data["__miniprofiler"] = p
	if ok {
		c.Input.Data["miniprofiler"] = p.Includes()
	}
}
Exemplo n.º 2
0
func (c *MiniProfilerContext) MiniProfileMiddleware(rw web.ResponseWriter, r *web.Request, next web.NextMiddlewareFunc) {
	ok := miniprofiler.Enable(r.Request)
	if ok && strings.HasPrefix(r.Request.URL.Path, miniprofiler.PATH) {
		miniprofiler.MiniProfilerHandler(rw, r.Request)
		return
	}
	p := miniprofiler.NewProfile(rw, r.Request, r.URL.Path)
	c.MiniProfilerTemplate = p.Includes()
	c.MiniProfilerTimer = p
	next(rw, r)
	if ok {
		p.Finalize()
	}
}
Exemplo n.º 3
0
func (c *Middleware) ServeHTTP(w traffic.ResponseWriter, r *traffic.Request, next traffic.NextMiddlewareFunc) {
	ok := miniprofiler.Enable(r.Request)
	if ok && strings.HasPrefix(r.Request.URL.Path, miniprofiler.PATH) {
		miniprofiler.MiniProfilerHandler(w, r.Request)
		return
	}
	p := miniprofiler.NewProfile(w, r.Request, r.URL.Path)
	w.SetVar("miniprofiler", p.Includes())
	w.SetVar("miniprofiler_timer", p)
	if nextMiddleware := next(); nextMiddleware != nil {
		nextMiddleware.ServeHTTP(w, r, next)
	}
	if ok {
		p.Finalize()
	}
	return
}
Exemplo n.º 4
0
func Filter(c *revel.Controller, fc []revel.Filter) {
	ok := miniprofiler.Enable(c.Request.Request)
	if ok && strings.HasPrefix(c.Request.Request.URL.Path, miniprofiler.PATH) {
		miniprofiler.MiniProfilerHandler(c.Response.Out, c.Request.Request)
		return
	}
	p := miniprofiler.NewProfile(c.Response.Out, c.Request.Request, c.Action)
	c.Args["miniprofiler"] = p
	if ok {
		c.RenderArgs["miniprofiler"] = p.Includes()
	}
	fc[0](c, fc[1:])
	if ok {
		p.SetName(c.Action)
		p.Finalize()
	}
}