// defaultMux tells mux to serve path using the default muxer. This is
// mostly useful to hook up things that register in the default muxer,
// and don't provide a convenient http.Handler entry point, such as
// expvar and http/pprof.
766567
func defaultMux(path string) corehttp.ServeOption {
	return func(node *core.IpfsNode, _ net.Listener, mux *http.ServeMux) (*http.ServeMux, error) {
		mux.Handle(path, http.DefaultServeMux)
		return mux, nil
	}
}
272359
func newMux(p packetConn) *mux {
	m := &mux{
		conn:             p,
		incomingChannels: make(chan NewChannel, 16),
		globalResponses:  make(chan interface{}, 1),
		incomingRequests: make(chan *Request, 16),
		errCond:          newCond(),
	}
	if debugMux {
		m.chanList.offset = atomic.AddUint32(&globalOff, 1)
	}

	go m.loop()
	return m
}
187627
func NewMux() ServeMux {
	r := httptreemux.New()
	r.EscapeAddedRoutes = true
	return &mux{
		router:  r,
		handles: make(map[string]MuxHandler),
	}
}
1139921
func (application *Application) NewServeMux() http.Handler {
	if len(application.Config.Handlers) == 0 {
		return middlewares.Apply(application.Config.Router)
	}

	wildcardRouter := wildcard_router.New()
	for _, handler := range application.Config.Handlers {
		wildcardRouter.AddHandler(handler)
	}
	wildcardRouter.AddHandler(application.Config.Router)

	return middlewares.Apply(wildcardRouter)
}
1107332
func DefaultPathEnv(platform string) string {
	if runtime.GOOS == "windows" {
		if platform != runtime.GOOS && LCOWSupported() {
			return defaultUnixPathEnv
		}
		// Deliberately empty on Windows containers on Windows as the default path will be set by
		// the container. Docker has no context of what the default path should be.
		return ""
	}
	return defaultUnixPathEnv

}
913088
func (m *Mux) DefaultServe(rw http.ResponseWriter, req *http.Request) {
	// Check if a route match
	if !m.parse(rw, req) {
		// Check if it's a static ressource
		if !m.staticRoute(rw, req) {
			// Check if the request path doesn't end with /
			if !m.validate(rw, req) {
				// Check if same route exists for another HTTP method
				if !m.otherMethods(rw, req) {
					m.HandleNotFound(rw, req)
				}
			}
		}
	}
}
1071125
func (m *Mux) PUT(path string, handler HandlerFunc) Handler {
	return m.Handler("PUT", path, handler)
}
1260150
func (m *mux) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	m.router.ServeHTTP(rw, req)
}
1362898
func NewMux() *http.ServeMux {
	mux := http.NewServeMux()
	mux.HandleFunc(BasePath+"/", func(w http.ResponseWriter, r *http.Request) {
		// this endpoint, as implemented in the standard library, doesn't set
		// its Content-Type header, so using this can confuse clients, especially
		// if gzipping...
		w.Header().Set("Content-Type", "text/html; charset=utf-8")
		pp.Index(w, r)
	})
	mux.HandleFunc(BasePath+"/cmdline", pp.Cmdline)
	mux.HandleFunc(BasePath+"/profile", pp.Profile)
	mux.HandleFunc(BasePath+"/symbol", pp.Symbol)
	mux.HandleFunc(BasePath+"/trace", pp.Trace)
	return mux
}
90306
func (s *Server) createMux() *mux.Router {
	m := mux.NewRouter()
	if utils.IsDebugEnabled() {
		profilerSetup(m, "/debug/")
	}

	glog.V(3).Infof("Registering routers")
	for _, apiRouter := range s.routers {
		for _, r := range apiRouter.Routes() {
			f := s.makeHTTPHandler(r.Handler())

			glog.V(3).Infof("Registering %s, %s", r.Method(), r.Path())
			m.Path(versionMatcher + r.Path()).Methods(r.Method()).Handler(f)
			m.Path(r.Path()).Methods(r.Method()).Handler(f)
		}
	}

	return m
}
522438
func (Pipe) Default(ctx *context.Context) error {
	return http.Defaults(ctx.Config.Puts)
}
335320
func (r *Request) Mux() *mux.Mux {
	mx := mux.New()
	r.Use(mx)
	return mx
}
869712
func (h Handler) ServeUnix(addr string, gid int) error {
	l, spec, err := newUnixListener(addr, gid)
	if err != nil {
		return err
	}
	if spec != "" {
		defer os.Remove(spec)
	}
	return h.Serve(l)
}
1125298
func ServeMux(m ServeMuxMap) {
	if len(os.Args) != 2 {
		fmt.Fprintf(os.Stderr,
			"Invoked improperly. This is an internal command that shouldn't\n"+
				"be manually invoked.\n")
		os.Exit(1)
	}

	opts, ok := m[os.Args[1]]
	if !ok {
		fmt.Fprintf(os.Stderr, "Unknown plugin: %s\n", os.Args[1])
		os.Exit(1)
	}

	Serve(opts)
}
1009278
func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	h, err := m.router.Route(r)
	if err != nil || h == nil {
		m.notFound.ServeHTTP(w, r)
		return
	}
	h.(http.Handler).ServeHTTP(w, r)
}
1338975
func stackedMux(useRealIP bool) *chi.Mux {
	mux := chi.NewRouter()
	if useRealIP {
		mux.Use(middleware.RealIP)
	}
	mux.Use(middleware.Logger)
	mux.Use(middleware.Recoverer)
	corsMW := cors.Default()
	mux.Use(corsMW.Handler)
	return mux
}
1218996
func ServeSwaggerUI(mux *http.ServeMux, swaggerJSON string, uiPath string) {
	prefix := path.Dir(uiPath)
	specURL := path.Join(prefix, "swagger.json")

	mux.HandleFunc(specURL, func(w http.ResponseWriter, r *http.Request) {
		_, _ = fmt.Fprint(w, swaggerJSON)
	})

	mux.Handle(uiPath, middleware.Redoc(middleware.RedocOpts{
		BasePath: prefix,
		SpecURL:  specURL,
		Path:     path.Base(uiPath),
	}, http.NotFoundHandler()))
}