// ServeHTTP recovers binlog service.
969896
func (h binlogRecover) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	binloginfo.DisableSkipBinlogFlag()
}
151638
func (h *Handler) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
	h.ServeHTTPC(h.StartingContext, rw, r)
}
1289561
func (f ErrorHandlerFunc) ServeHTTP(w http.ResponseWriter, r *http.Request, err error) {
	f(w, r, err)
}
1107325
func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	h.serveHTTPForOp(w, r, OpAll)
}
587407
func (fs FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
	if r.Method != "GET" && r.Method != "HEAD" {
		return http.StatusMethodNotAllowed, nil
	}
	return fs.serveFile(w, r)
}
1178247
func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	if len(s.finalizer) > 0 {
		iw := &interceptingWriter{w, http.StatusOK, 0}
		defer func() {
			ctx = context.WithValue(ctx, ContextKeyResponseHeaders, iw.Header())
			ctx = context.WithValue(ctx, ContextKeyResponseSize, iw.written)
			for _, f := range s.finalizer {
				f(ctx, iw.code, r)
			}
		}()
		w = iw
	}

	for _, f := range s.before {
		ctx = f(ctx, r)
	}

	request, err := s.dec(ctx, r)
	if err != nil {
		s.errorHandler.Handle(ctx, err)
		s.errorEncoder(ctx, err, w)
		return
	}

	response, err := s.e(ctx, request)
	if err != nil {
		s.errorHandler.Handle(ctx, err)
		s.errorEncoder(ctx, err, w)
		return
	}

	for _, f := range s.after {
		ctx = f(ctx, w)
	}

	if err := s.enc(ctx, w, response); err != nil {
		s.errorHandler.Handle(ctx, err)
		s.errorEncoder(ctx, err, w)
		return
	}
}
795307
func (k *Kite) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	k.muxer.ServeHTTP(w, req)
}
1295352
func (a *Application) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// log all unhandled panic's
	defer func() {
		if r := recover(); r != nil {
			fmt.Printf("%v", r)
			a.Emit("error", r)
			log.Panic(r)
		}
	}()

	ctx := makeCtx(req, w)
	request := ctx.Req
	response := ctx.Res

	defer response.flush()

	if req.ContentLength > a.Conf.App.MaxBodyBytes {
		log.Errorf("Received too large body. Size: %d, URL %s, Method: %s", req.ContentLength, req.URL.Path, req.Method)

		response.Status = http.StatusExpectationFailed
		response.Json(map[string]string{
			"error": "request body too large",
		})

		return
	}

	req.Body = http.MaxBytesReader(w, req.Body, a.Conf.App.MaxBodyBytes)

	///////////////////////////////////////////////////////////////////
	// Static File Serving
	///////////////////////////////////////////////////////////////////
	if a.static != nil {
		// check if file can be served
		file, err := a.static.match(req.URL.Path)

		if err == nil {
			h := func(ctx *Ctx) (int, error) {
				response.SkipFlush()
				return 200, response.serveFile(file)
			}

			fn := compose(merge(a.middlewares, []appliable{handler(h)}))
			fn(ctx)
			return
		}

		log.Debug("result not found in static")
	}

	///////////////////////////////////////////////////////////////////
	// Route Matching
	///////////////////////////////////////////////////////////////////
	route, err := a.match(request)

	if err != nil {
		log.Debugf("route %s not found. Error: %s", req.URL.Path, err.Error())

		// dummy route handler
		h := func(ctx *Ctx) (int, error) {
			return http.StatusNotFound, nil
		}

		compose(merge(a.middlewares, []appliable{handler(h)}))(ctx)
	} else {
		ctx.Req.ResolvedRoute = route.path
		route.fnChain(ctx)
	}
}
265474
func (w *wrappedMux) ServeHTTP(resp http.ResponseWriter, req *http.Request) {
	w.handler.ServeHTTP(resp, req)
}
998257
func (h httpHandlerCustom) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	h.F(h.ctx, w, r)
}
864202
func (h *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	var update Update
	err := json.NewDecoder(r.Body).Decode(&update)
	if err != nil {
		h.bot.debug(fmt.Errorf("cannot decode update: %v", err))
		return
	}
	h.dest <- update
}
1183813
func (fe *T) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	fe.getHandler().ServeHTTP(w, r)
}
369960
func (mung *Mung) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
	mung.handle(rw, r)
}
821940
func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.URL.Path == m.ServiceProvider.MetadataURL.Path {
		buf, _ := xml.MarshalIndent(m.ServiceProvider.Metadata(), "", "  ")
		w.Header().Set("Content-Type", "application/samlmetadata+xml")
		w.Write(buf)
		return
	}

	if r.URL.Path == m.ServiceProvider.AcsURL.Path {
		r.ParseForm()
		assertion, err := m.ServiceProvider.ParseResponse(r, m.getPossibleRequestIDs(r))
		if err != nil {
			if parseErr, ok := err.(*saml.InvalidResponseError); ok {
				m.ServiceProvider.Logger.Printf("RESPONSE: ===\n%s\n===\nNOW: %s\nERROR: %s",
					parseErr.Response, parseErr.Now, parseErr.PrivateErr)
			}
			http.Error(w, http.StatusText(http.StatusForbidden), http.StatusForbidden)
			return
		}

		m.Authorize(w, r, assertion)
		return
	}

	http.NotFoundHandler().ServeHTTP(w, r)
}
1183227
func (h *logSinkHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
	// If the modelUUID from the request is empty, fallback to the one in
	// the logsink handler (controller UUID)
	resolvedModelUUID := h.modelUUID
	if modelUUID := httpcontext.RequestModelUUID(req); modelUUID != "" {
		resolvedModelUUID = modelUUID
	}

	handler := func(socket *websocket.Conn) {
		h.metrics.TotalConnections().Inc()
		h.metrics.Connections().Inc()
		defer h.metrics.Connections().Dec()

		defer socket.Close()
		endpointVersion, err := h.getVersion(req)
		if err != nil {
			h.sendError(socket, req, err)
			return
		}
		writer, err := h.newLogWriteCloser(req)
		if err != nil {
			h.sendError(socket, req, err)
			return
		}
		defer writer.Close()

		// If we get to here, no more errors to report, so we report a nil
		// error.  This way the first line of the socket is always a json
		// formatted simple error.
		h.sendError(socket, req, nil)

		// Here we configure the ping/pong handling for the websocket so the
		// server can notice when the client goes away. Older versions did not
		// respond to ping control messages, so don't try.
		var tickChannel <-chan time.Time
		if endpointVersion > 0 {
			socket.SetReadDeadline(time.Now().Add(websocket.PongDelay))
			socket.SetPongHandler(func(string) error {
				logger.Tracef("pong logsink %p", socket)
				socket.SetReadDeadline(time.Now().Add(websocket.PongDelay))
				return nil
			})
			ticker := time.NewTicker(websocket.PingPeriod)
			defer ticker.Stop()
			tickChannel = ticker.C
		} else {
			socket.SetReadDeadline(time.Now().Add(vZeroDelay))
		}

		stopReceiving, closer := h.newStopChannel()
		defer closer()
		logCh := h.receiveLogs(socket, endpointVersion, resolvedModelUUID, stopReceiving)
		for {
			select {
			case <-h.abort:
				return
			case <-tickChannel:
				deadline := time.Now().Add(websocket.WriteWait)
				logger.Tracef("ping logsink %p", socket)
				if err := socket.WriteControl(gorillaws.PingMessage, []byte{}, deadline); err != nil {
					// This error is expected if the other end goes away. By
					// returning we clean up the strategy and close the socket
					// through the defer calls.
					logger.Debugf("failed to write ping: %s", err)
					// Bump the ping failure count.
					h.metrics.PingFailureCount(resolvedModelUUID).Inc()
					return
				}
			case m, ok := <-logCh:
				if !ok {
					h.mu.Lock()
					defer h.mu.Unlock()
					h.receiverStopped = true
					return
				}

				if err := writer.WriteLog(m); err != nil {
					h.sendError(socket, req, err)
					// Increment the number of failure cases per modelUUID, that
					// we where unable to write a log to - note: we won't see
					// why the failure happens, only that it did happen. Maybe
					// we should add a trace log here. Developer mode for send
					// error might help if it was enabled at first ?
					h.metrics.LogWriteCount(resolvedModelUUID, metricLogWriteLabelFailure).Inc()
					return
				}

				// Increment the number of successful modelUUID log writes, so
				// that we can see what's a success over failure case
				h.metrics.LogWriteCount(resolvedModelUUID, metricLogWriteLabelSuccess).Inc()
			}
		}
	}
	websocket.Serve(w, req, handler)
}
292573
func (a *APIServerHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	a.FullHandlerChain.ServeHTTP(w, r)
}
416412
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	defer func() {
		// We absolutely need to be sure we stay alive up here,
		// even though, in theory, the errors middleware does this.
		if rec := recover(); rec != nil {
			log.Printf("[PANIC] %v", rec)
			DefaultErrorFunc(w, r, http.StatusInternalServerError)
		}
	}()

	w.Header().Set("Server", "Caddy")

	sanitizePath(r)

	status, _ := s.serveHTTP(w, r)

	// Fallback error response in case error handling wasn't chained in
	if status >= 400 {
		DefaultErrorFunc(w, r, status)
	}
}