MCPcopy Create free account
hub / github.com/quay/clair / ServeHTTP

Method ServeHTTP

httptransport/concurrentlimit.go:36–54  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

34}
35
36func (l *limitHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
37 sem, endpt := l.Check(r)
38 if sem != nil {
39 if !sem.TryAcquire(1) {
40 concurrentLimitedCounter.WithLabelValues(endpt, r.Method).Add(1)
41 ctx := r.Context()
42 zlog.Info(ctx).
43 Str("remote_addr", r.RemoteAddr).
44 Str("method", r.Method).
45 Str("request_uri", r.RequestURI).
46 Int("status", http.StatusTooManyRequests).
47 Msg("rate limited HTTP request")
48
49 apiError(ctx, w, http.StatusTooManyRequests, "server handling too many requests")
50 }
51 defer sem.Release(1)
52 }
53 l.Next.ServeHTTP(w, r)
54}

Callers

nothing calls this directly

Calls 4

apiErrorFunction · 0.85
AddMethod · 0.80
InfoMethod · 0.80
CheckMethod · 0.65

Tested by

no test coverage detected