// Adding new middleware into chain of middlewares.
192694
func (m *interceptor) Use(fn Middleware) {
	m.middlewares = append(m.middlewares, appliable(&fn))
}
1322341
func WrapMiddleware(m func(http.Handler) http.Handler) MiddlewareFunc {
	return func(next HandlerFunc) HandlerFunc {
		return func(c Context) (err error) {
			m(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
				c.SetRequest(r)
				err = next(c)
			})).ServeHTTP(c.Response(), c.Request())
			return
		}
	}
}
48262
func (api *API) UseMiddleware(middleware ...HandlerFunc) {
	api.middlewares = append(api.middlewares, middleware...)
}
154476
func (s *ServeMux) HandlerAndMiddleware(r *http.Request) (http.Handler, []Middleware, string) {
	// create a new execution so fields will live outside of this function
	ex := newExecution()
	s.getAll(r, ex)
	return ex.handler, ex.middleware, ex.pattern
}
898627
func (e *Environment) InstallHandlersWithMiddleware(r *router.Router, base router.MiddlewareChain) {
	warmup.InstallHandlers(r, base)

	if e.ExtraHandlers != nil {
		e.ExtraHandlers(r, base)
	}
}
1144105
func (n NextConstructor) CreateMiddleware(next ContextHandler) ContextHandler {
	return HandlerFunc(func(ctx context.Context, rw http.ResponseWriter, r *http.Request) {
		n(ctx, rw, r, next)
	})
}
684052
func (m *ServeMux) Middleware(f MiddlewareFunc) {
	m.middlewares = append(m.middlewares, f)
}
1319460
func New(ctx context.Context, next http.Handler, config config.StripPrefixRegex, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")

	stripPrefix := stripPrefixRegex{
		next:   next,
		router: mux.NewRouter(),
		name:   name,
	}

	for _, prefix := range config.Regex {
		stripPrefix.router.PathPrefix(prefix)
	}

	return &stripPrefix, nil
}
1150987
func NewMiddleware(limiter *limiter.Limiter, options ...Option) *Middleware {
	middleware := &Middleware{
		Limiter:        limiter,
		OnError:        DefaultErrorHandler,
		OnLimitReached: DefaultLimitReachedHandler,
	}

	for _, option := range options {
		option.apply(middleware)
	}

	return middleware
}
2675
func chainMiddleware(el *list.Element) http.HandlerFunc {
	// The last element of the middlewares chain is nil.
	if el == nil {
		return func(rw http.ResponseWriter, r *http.Request) {}
	}
	return func(rw http.ResponseWriter, r *http.Request) {
		el.Value.(Middleware).ServeHTTP(rw, r, chainMiddleware(el.Next()))
	}
}
487837
func NewChain(handlerArray ...MiddlewareHandlerFunc) *Chain {
	c := new(Chain)
	c.middlewareHandlers = handlerArray
	return c
}
522806
func (q *Queue) Middleware(ctx *neptulon.ReqCtx) error {
	q.middlewareChan <- middlewareChan{userID: ctx.Conn.Session.Get("userid").(string), connID: ctx.Conn.ID}
	return ctx.Next()
}
92923
func NewAPIKeyCheckMiddleware(url string) *APIKeyCheckMiddleware {
	keycheck := New(url)
	middleware := &APIKeyCheckMiddleware{Keycheck: keycheck}
	return middleware
}
1098896
func Middleware() middleware.Middleware {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			nw := &responseWriter{
				ResponseWriter: w,
				t:              time.Now(),
			}
			h.ServeHTTP(nw, r)
		})
	}
}
691513
func New(ctx context.Context, next http.Handler, config config.Chain, builder chainBuilder, name string) (http.Handler, error) {
	middlewares.GetLogger(ctx, name, typeName).Debug("Creating middleware")

	middlewareChain := builder.BuildChain(ctx, config.Middlewares)
	return middlewareChain.Then(next)
}
881563
func (e *Echo) chainMiddleware() {
	if e.head != nil {
		return
	}
	e.head = e.router.Handle(nil)
	for i := len(e.middleware) - 1; i >= 0; i-- {
		e.head = e.ValidMiddleware(e.middleware[i]).Handle(e.head)
	}
}
315292
func (c *Chain) Add(f ...interface{}) {
	for _, h := range f {
		switch v := h.(type) {
		case func(http.Handler) http.Handler:
			c.Use(v)
		case func(HandlerC) HandlerC:
			c.UseC(v)
		default:
			panic("Adding invalid handler to the middleware chain")
		}
	}
}