Commit 1ba95183 by Agnès Toulet Committed by GitHub

HTTPServer: add possibility to use additional middlewares (#26514)

parent b12d08d9
......@@ -53,6 +53,7 @@ type HTTPServer struct {
context context.Context
streamManager *live.StreamManager
httpSrv *http.Server
middlewares []macaron.Handler
RouteRegister routing.RouteRegister `inject:""`
Bus bus.Bus `inject:""`
......@@ -82,6 +83,10 @@ func (hs *HTTPServer) Init() error {
return nil
}
func (hs *HTTPServer) AddMiddleware(middleware macaron.Handler) {
hs.middlewares = append(hs.middlewares, middleware)
}
func (hs *HTTPServer) Run(ctx context.Context) error {
hs.context = ctx
......@@ -323,6 +328,10 @@ func (hs *HTTPServer) addMiddlewaresAndStaticRoutes() {
}
m.Use(middleware.HandleNoCacheHeader())
for _, mw := range hs.middlewares {
m.Use(mw)
}
}
func (hs *HTTPServer) metricsEndpoint(ctx *macaron.Context) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment