func()

in pkg/handlers/v2/handler.go [27:62]


func (h *V2Handler) Handle(c pcontext.Context) {
	l := pcontext.Logger(c).With().Bool("p2p", pcontext.IsRequestFromAPeer(c)).Logger()
	l.Debug().Msg("v2 handler start")
	s := time.Now()
	defer func() {
		dur := time.Since(s)
		h.metricsRecorder.RecordRequest(c.Request.Method, "oci", dur.Seconds())
		l.Debug().Dur("duration", dur).Str("ns", c.GetString(pcontext.NamespaceCtxKey)).Str("ref", c.GetString(pcontext.ReferenceCtxKey)).Str("digest", c.GetString(pcontext.DigestCtxKey)).Msg("v2 handler stop")
	}()

	p := path.Clean(c.Request.URL.Path)
	if p == "/v2" || p == "/v2/" {
		if c.Request.Method != http.MethodGet && c.Request.Method != http.MethodHead {
			c.Status(http.StatusNotFound)
			return
		}
		c.Status(http.StatusOK)
		return
	}

	err := h.fill(c)
	if err != nil {
		l.Debug().Err(err).Msg("failed to fill context")
		// nolint
		c.AbortWithError(http.StatusBadRequest, err)
		return
	}

	if pcontext.IsRequestFromAPeer(c) {
		h.registry.Handle(c)
		return
	} else {
		h.proxy.Handle(c)
		return
	}
}