K8s: use contexthandler in standalone handler chain (#90102)
This commit is contained in:
@@ -139,6 +139,17 @@ func mwFromHandler(handler Handler) Middleware {
|
||||
}
|
||||
}
|
||||
|
||||
// a convenience function that is provided for users of contexthandler package (standalone apiservers)
|
||||
// who have an implicit dependency on Macron in context but don't want to take a dependency on
|
||||
// router additionally
|
||||
func EmptyMacronMiddleware(next http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(writer http.ResponseWriter, request *http.Request) {
|
||||
m := New()
|
||||
c := m.createContext(writer, request)
|
||||
next.ServeHTTP(writer, c.Req) // since c.Req has the newer context attached
|
||||
})
|
||||
}
|
||||
|
||||
func (m *Macaron) createContext(rw http.ResponseWriter, req *http.Request) *Context {
|
||||
// NOTE: we have to explicitly copy the middleware chain here to avoid
|
||||
// passing a shared slice to the *Context, which leads to racy behavior in
|
||||
|
||||
Reference in New Issue
Block a user