// Handler return HTTP handler representation of this middleware
7271
func (om *ClientIDMiddleware) Handler(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		var clientID string

		accessToken := om.GetAccessToken(r)

		token, err := oauth2.GetValidJWT(r, security.JWTPublicKey)
		if err != nil {
			log.Error("Failed to get valid JWT: ", err)
			http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
			return
		}
		if token != nil {
			clientID = token.Claims["azp"].(string)

		} else if accessToken != "" {
			oauthMgr := oauthservice.NewManager(r)
			at, err := oauthMgr.GetAccessToken(accessToken)
			if err != nil {
				log.Error("Failed to get access token: ", err)
				http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
				return
			}
			if at == nil {
				http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
				return
			}
			clientID = at.ClientID
		} else {
			if webuser, ok := context.GetOk(r, "webuser"); ok {
				if parsedusername, ok := webuser.(string); ok && parsedusername != "" {
					clientID = "itsyouonline"
				}
			}
		}
		if clientID == "" {
			http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
			return
		}

		context.Set(r, "client_id", clientID)

		next.ServeHTTP(w, r)
	})
}
1256731
func Handle(route string, method string, httpHandler http.Handler) {
	mainServer.Handle(route, method, httpHandler)
}
253296
func (h *Handler) Handle(err error) {
	var interfaces []raven.Interface

	// Get HTTP request (if any)
	if req, ok := httperr.HTTPRequest(err); ok {
		interfaces = append(interfaces, raven.NewHttp(req))
	}

	packet := raven.NewPacketWithExtra(
		err.Error(),
		keyvals.ToMap(emperror.Context(err)),
		append(
			interfaces,
			raven.NewException(
				err,
				raven.GetOrNewStacktrace(emperror.ExposeStackTrace(err), 1, 3, h.client.IncludePaths()),
			),
		)...,
	)

	eventID, ch := h.client.Capture(packet, nil)

	if h.sendSynchronously && eventID != "" {
		<-ch
	}
}
597566
func (d *DebugAssets) Handler() http.Handler {
	return http.FileServer(NewDir(d.Dir, d.Default))
}
893113
func (s *Server) Handle(method string, handlerFunc interface{}) {
	addHandler(s.handlers, method, handlerFunc)
}
325173
func Handler(c Config) (http.Handler, error) {
	h, _, err := HandlerAPI(c)
	return h, err
}
980954
func (mr *MountableRouter) Handler(method string, path string, handler http.Handler) {
	mr.Delegate.Handler(method, libpath.Join(mr.Prefix, path), handler)
}
285213
func Handler(as *assets.Assets, notFound http.Handler, index, origDef, newDef string) http.Handler {
	modtime := time.Now()

	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		p := r.URL.Path
		if p != "" && p[0] == '/' {
			p = p[1:]
		}

		var bs []byte
		var err error

		switch p {
		case "", index:
			bs, err = as.ModifiedAsset(index, origDef, newDef)
		default:
			bs, err = as.Asset(p)
		}
		if err != nil {
			notFound.ServeHTTP(w, r)
			return
		}

		http.ServeContent(w, r, p, modtime, bytes.NewReader(bs))
	})
}
1363244
func Handle(handler Handler, err error) {
	if err != nil {
		handler.Handle(err)
	}
}
739235
func (h HTTPRouter) Handle(protocol, route string, handler HandlerFunc) {
	wrappedCallback := func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
		params := map[string]string{}
		for _, p := range ps {
			params[p.Key] = p.Value
		}

		handler(w, r, params, make(map[string]interface{}))
	}

	h.router.Handle(protocol, route, wrappedCallback)
}
544728
func (r *Route) Handler(h Handler) *Route {
	r.route.Handler(r.handler(h))
	return r
}
1127476
func (a *Auth) Handler(h http.Handler) http.Handler {
	a.ensureDefaults()
	return &handler{Auth: a, handler: h}
}
1119165
func (om *Oauth2oauth_2_0Middleware) Handler(next http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {

		var atscopestring string
		var username string
		accessToken := om.GetAccessToken(r)
		if accessToken != "" {
			//TODO: cache
			oauthMgr := oauthservice.NewManager(r)
			at, err := oauthMgr.GetAccessToken(accessToken)
			if err != nil {
				log.Error(err)
				http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
				return
			}
			if at == nil {
				http.Error(w, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
				return
			}
			atscopestring = at.Scope
			username = at.Username
		} else {
			w.WriteHeader(401)
			return
		}
		scopes := []string{}

		contractID := mux.Vars(r)["contractId"]
		contractMngr := contractdb.NewManager(r)
		isParticipant, err := contractMngr.IsParticipant(contractID, username)
		if err != nil {
			log.Error(err)
			http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
			return
		}
		if isParticipant {
			scopes = append(scopes, "contract:participant")
			scopes = append(scopes, "contract:read")
		}
		log.Debug("Available scopes: ", scopes)
		log.Debug("Atscopestring scope: ", atscopestring)

		// check scopes
		if !om.CheckScopes(scopes) {
			w.WriteHeader(403)
			return
		}

		next.ServeHTTP(w, r)
	})
}
980777
func (m *Mux) Handler() c.HandlerFunc {
	return func(ctx *c.Context, h c.Handler) {
		if !m.Match(ctx) {
			h.Next(ctx)
			return
		}

		ctx = m.Middleware.Run(ctx.GetString("$phase"), ctx)
		if ctx.Error != nil {
			h.Error(ctx, ctx.Error)
			return
		}
		if ctx.Stopped {
			h.Stop(ctx)
			return
		}

		h.Next(ctx)
	}
}
114945
func (m *Manager) Middleware() func(http.Handler) http.Handler {
	return func(h http.Handler) http.Handler {
		return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
			rm := &scopedManager{
				Manager:        m,
				ResponseWriter: w,
				r:              r,
				storage:        make(map[string]*Session),
			}

			ctx := context.WithValue(r.Context(), scopedManagerKey{}, rm)
			h.ServeHTTP(rm, r.WithContext(ctx))

			rm.MustSaveAll()
		})
	}
}
237706
func (mw *Stats) Handler(h http.Handler) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		beginning, recorder := mw.Begin(w)

		h.ServeHTTP(recorder, r)

		mw.End(beginning, WithRecorder(recorder))
	})
}
978261
func (mux *TypeMux) Handler(r *Request) Handler {
	return mux.mux.Handler(r)
}