// GetMux returns the mux with handlers for httpbin endpoints registered.
185983
func GetMux() *mux.Router {

	r := mux.NewRouter()
	r.HandleFunc(`/`, HomeHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/ip`, IPHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/user-agent`, UserAgentHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/headers`, HeadersHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/get`, GetHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/post`, PostHandler).Methods(http.MethodPost)
	r.HandleFunc(`/redirect/{n:[\d]+}`, RedirectHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/absolute-redirect/{n:[\d]+}`, AbsoluteRedirectHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/redirect-to`, RedirectToHandler).Methods(http.MethodGet, http.MethodHead).Queries("url", "{url:.+}")
	r.HandleFunc(`/status/{code:[\d]+}`, StatusHandler)
	r.HandleFunc(`/bytes/{n:[\d]+}`, BytesHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/delay/{n:\d+(?:\.\d+)?}`, DelayHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/stream/{n:[\d]+}`, StreamHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/drip`, DripHandler).Methods(http.MethodGet, http.MethodHead).Queries(
		"numbytes", `{numbytes:\d+}`,
		"duration", `{duration:\d+(?:\.\d+)?}`)
	r.HandleFunc(`/cookies`, CookiesHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/cookies/set`, SetCookiesHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/cookies/delete`, DeleteCookiesHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/cache`, CacheHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/cache/{n:[\d]+}`, SetCacheHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/gzip`, GZIPHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/deflate`, DeflateHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/html`, HTMLHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/xml`, XMLHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/robots.txt`, RobotsTXTHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/deny`, DenyHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/basic-auth/{u}/{p}`, BasicAuthHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/hidden-basic-auth/{u}/{p}`, HiddenBasicAuthHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/image/gif`, GIFHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/image/png`, PNGHandler).Methods(http.MethodGet, http.MethodHead)
	r.HandleFunc(`/image/jpeg`, JPEGHandler).Methods(http.MethodGet, http.MethodHead)
	return r
}
1178397
func (g *GoHttpServer) handleMux(w http.ResponseWriter, r *http.Request) {
	if maxRequestSize := int64(Config.IntDefault("http.maxrequestsize", 0)); maxRequestSize > 0 {
		r.Body = http.MaxBytesReader(w, r.Body, maxRequestSize)
	}

	upgrade := r.Header.Get("Upgrade")
	context := g.goContextStack.Pop().(*GoContext)
	defer func() {
		g.goContextStack.Push(context)
	}()
	context.Request.SetRequest(r)
	context.Response.SetResponse(w)

	if upgrade == "websocket" || upgrade == "Websocket" {
		websocket.Handler(func(ws *websocket.Conn) {
			//Override default Read/Write timeout with sane value for a web socket request
			if err := ws.SetDeadline(time.Now().Add(time.Hour * 24)); err != nil {
				serverLogger.Error("SetDeadLine failed:", err)
			}
			r.Method = "WS"
			context.Request.WebSocket = ws
			context.WebSocket = &GoWebSocket{Conn: ws, GoResponse: *context.Response}
			g.ServerInit.Callback(context)
		}).ServeHTTP(w, r)
	} else {
		g.ServerInit.Callback(context)
	}
}
1069158
func (mock *HttpClientMock) Get(url string) (*http.Response, error) {
	if mock.GetFunc == nil {
		panic("moq: HttpClientMock.GetFunc is nil but httpClient.Get was just called")
	}
	callInfo := struct {
		URL string
	}{
		URL: url,
	}
	lockhttpClientMockGet.Lock()
	mock.calls.Get = append(mock.calls.Get, callInfo)
	lockhttpClientMockGet.Unlock()
	return mock.GetFunc(url)
}
378201
func (m *Mux) GET(patt string, handlers ...http.HandlerFunc) {
	m.add("GET", patt, handlers)
	m.add("HEAD", patt, handlers)
}
611004
func (f *FastHTTPServer) handleMux(ctx *fasthttp.RequestCtx) {
	// TODO limit max size of body that can be read
	//if maxRequestSize := int64(revel.Config.IntDefault("http.maxrequestsize", 0)); maxRequestSize > 0 {
	//   buffer := &bytes.Buffer{}
	//   err := ctx.Request.ReadLimitBody(buffer,maxRequestSize)
	//   if err!=nil {
	//       // Send the error back to the client
	//       ctx.SetStatusCode(http.StatusRequestEntityTooLarge)
	//       return
	//   }
	//}
	context := fastHttpContextStack.Pop().(*FastHttpContext)
	defer func() {
		fastHttpContextStack.Push(context)
	}()
	context.SetContext(ctx)
	f.ServerInit.Callback(context)
}
774514
func (s *Server) GetInfoMux() *bone.Mux {
	mux := bone.New()

	mux.Get("/info", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		ci := s.getInfo()
		js, err := json.Marshal(ci)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		w.Header().Set("Content-Type", "application/json")
		w.Write(js)
	}))

	mux.Get("/containers/:id", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		containerID := bone.GetValue(req, "id")
		ci, err := s.getContainerInfo(containerID, s.GetContainer, s.getInfraContainer, s.getSandbox)
		if err != nil {
			switch err {
			case errCtrNotFound:
				http.Error(w, fmt.Sprintf("can't find the container with id %s", containerID), http.StatusNotFound)
			case errCtrStateNil:
				http.Error(w, fmt.Sprintf("can't find container state for container with id %s", containerID), http.StatusInternalServerError)
			case errSandboxNotFound:
				http.Error(w, fmt.Sprintf("can't find the sandbox for container id %s", containerID), http.StatusNotFound)
			default:
				http.Error(w, err.Error(), http.StatusInternalServerError)
			}
			return
		}
		js, err := json.Marshal(ci)
		if err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		w.Header().Set("Content-Type", "application/json")
		w.Write(js)
	}))

	return mux
}
896111
func HTTPGet(httpUrl string) ([]byte, error) {

	r, err := http.Get(httpUrl)

	if err != nil {
		return nil, err
	}

	defer r.Body.Close()

	if err != nil {
		return nil, err
	}

	// read the response and check
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		return nil, err
	}

	return body, nil
}
603085
func (ctx *Context) GETParams() map[string][]string {
	res := make(map[string][]string)
	ctx.Request.URI().QueryArgs().VisitAll(func(key, value []byte) {
		res[string(key)] = append(res[string(key)], string(value))
	})
	return res
}
405523
func (sm *ServeMux) HandleFunc(pattern string, handler func(http.ResponseWriter, *http.Request) error) {
	sm.ServeMux.Handle(pattern, sm.HandlerFunc(handler))
}
172764
func (r *Route) GetFunc(f http.HandlerFunc) *Route {
	return r.Get(http.HandlerFunc(f))
}
1260150
func (m *mux) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
	m.router.ServeHTTP(rw, req)
}
927820
func (m *Mux) HandleFunc(expr string, handler func(http.ResponseWriter, *http.Request)) error {
	return m.Handle(expr, http.HandlerFunc(handler))
}
411456
func NewServeMux(static string) *http.ServeMux {
	mux := http.NewServeMux()
	staticDir := http.FileServer(http.Dir(static))
	mux.Handle("/", staticDir)
	mux.Handle("/api/", http.StripPrefix("/api", *api.MakeHandler()))
	return mux
}
1111722
func SimpleMuxer(fx func(Publisher, interface{})) Handler {
	return func(r Publisher, err error, data interface{}) {
		if err != nil {
			r.ReplyError(err)
			return
		}

		fx(r, data)
	}
}
177648
func (r *Router) GetFunc(pattern string, fn http.HandlerFunc) Route {
	return r.Get(pattern, http.HandlerFunc(fn))
}
831191
func (s *Server) createMux() *mux.Router {
	m := mux.NewRouter()

	logrus.Debug("Registering routers")
	for _, apiRouter := range s.routers {
		for _, r := range apiRouter.Routes() {
			f := s.makeHTTPHandler(r.Handler())

			logrus.Debugf("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)
		}
	}

	debugRouter := debug.NewRouter()
	s.routers = append(s.routers, debugRouter)
	for _, r := range debugRouter.Routes() {
		f := s.makeHTTPHandler(r.Handler())
		m.Path("/debug" + r.Path()).Handler(f)
	}

	notFoundHandler := httputils.MakeErrorHandler(pageNotFoundError{})
	m.HandleFunc(versionMatcher+"/{path:.*}", notFoundHandler)
	m.NotFoundHandler = notFoundHandler
	m.MethodNotAllowedHandler = notFoundHandler

	return m
}
1281785
func (f *FastHTTPServer) handleAppMux(ctx *fasthttp.RequestCtx) (result bool) {
	// Check the prefix and split them
	cpath := string(ctx.Path())
	requestPath := path.Clean(cpath)
	if handler, hasHandler := f.HttpMuxList.Find(requestPath); hasHandler {
		result = true
		clientIP := HttpClientIP(ctx)
		localLog := serverLog.New("ip", clientIP,
			"path", cpath, "method", string(ctx.Method()))
		defer func() {
			if err := recover(); err != nil {
				localLog.Error("An error was caught using the handler", "path", requestPath, "error", err)
				fmt.Fprintf(ctx, "Unable to handle response for third part mux %v", err)
				ctx.Response.SetStatusCode(http.StatusInternalServerError)
				return
			}
		}()
		start := time.Now()
		handler.(fasthttp.RequestHandler)(ctx)
		localLog.Info("Request Stats",
			"start", start,
			"duration_seconds", time.Since(start).Seconds(), "section", "requestlog",
		)
		return
	}
	return
}